Jump to content
Sir Reng

[Resolvido] Comprimento dos lados de um triângulo

Recommended Posts

Sir Reng

Boas.

Venho cá mais uma vez postar uma dúvida :P

Estou a tentar resolver exercicios de Haskell e estava a conseguir até agora.

Exercicio:

(a) Defina uma funcão que recebe 3 pontos que são os vertices de um triângulo e devolve um tuplo com o comprimento dos seus lados.

module Tentativa where
type Ponto = (Float,Float)
compTri :: (Ponto,Ponto,Ponto) -> (Float,Float,Float)
compTri (x1,y1) (x2,y2) (x3,y3) = (sqrt ((x2-x1)^2+(y2-y1)^2)),(sqrt ((x3-x2)^2+(y3-y2)^2)),(sqrt ((x3-x1)^2+(y3-y1)^2))

Erro que deu no Haskell:

Tentativa.hs:4:10: Parse error in pattern: (x1, y1)
Failed, modules loaded: none.

Edited by pwseo
formatação, syntax highlight.

Share this post


Link to post
Share on other sites
Sir Reng

Pronto, já consegui resolver.

Usei o código seguinte:

type Ponto = (Float,Float)
compLados :: Ponto -> Ponto -> Ponto -> (Float, Float, Float)
compLados a b c = (distancia a c, distancia b c, distancia a b)

(Sorry Double-Post)

Edited by pwseo
syntax highlight.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.