Doubt Error Tree in Haskell

Asked

Viewed 41 times

1

My teacher, in a matter of Haskell asked to set tree in the following way:

inserir a descrição da imagem aqui

Being that defining this way gives this error:

inserir a descrição da imagem aqui

And in many corners of the internet, the tree in Haskell they define using Data as the image below:

inserir a descrição da imagem aqui

Then I wonder if the teacher is correct in declaring tree this way, because the way he asked us to define the error in the compiler.

1 answer

3


You are correct in your suspicion. The keyword type should not have been used in this case. The correct is data.

Briefly:

In Haskell, we have three basic ways to type:

  • Using data for new types.
  • Using type to declare synonyms of types, i.e., alternative names for existing types.
  • Using newtype to define new types equivalent to existing types.

I recommend you read more about type reporting, as the type system is a key part of Haskell. You can start with Wikibook in English, where I got that reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.