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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • 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.