Jump to content

expressão where e Cabal


genesis001
 Share

Recommended Posts

Boas,

queria saber se alguém me consegue esclarecer o seguinte:

quando utilizamos a expressão where, a ordem das equações que a seguem importa, certo? Como é que sabemos essa ordem?

Exemplificando:

Se introduzir a seguinte função num script e em seguida abrir o ficheiro .hs não há problemas:

testa y = f b + f y + f a + 3 

    where (a,😕 = (3*c, f 2)

              c = 10

              f x = x + 7*c

mas se trocar a ordem das equações:

testa y = f b + f y + f a + 3 

        where (a,😁 = (3*c, f 2)

                    f x = x + 7*c

                    c = 10

aparece o seguinte erro: parse error on input '='

Não consigo determinar qual é que tem que ser a ordem das equações para que não apareça o erro...

Por exemplo na seguinte função acontece-me o mesmo:

nraizes :: Double->Double->Double->Double

nraizes a b c

| d < 0 = 0

| d > 0 = 2

| d == 0 = 1

    where d = b^2 - 4*a*c

raizes :: Double->Double->Double->[Double]

raizes a b c

    | (nraizes a b c == 2) = [r1,r2]

              where  r1 = (-b + r)/(2*a)

                          r2 = (-b - r)/(2*a)

                          r = sqrt d

                          d = b^2 - 4*a*c

    | nraizes a b c == 0 = [error "raizes imaginarias"]

    | nraizes a b c == 1 = (-b / (2*a)):[]

E alguém consegue explicar-me como é que se instala um cabal?

Agradeço a ajuda

Link to comment
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
 Share

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