Doubt Error Tree in Haskell

1

My teacher in a haskell question asked to define tree as follows:

Beingthatsettingthiswaygivesthiserror:

Andinmanycornersoftheinternet,thehaskelltreetheydefineusingDataastheimagebelow:

So I would like to know if the teacher is correct in declaring tree this way because of the way he asked us to define the error in the compiler.

    
asked by anonymous 08.04.2018 / 21:31

1 answer

3

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

In summary:

  

In Haskell, we have three basic ways to declare types:

     
  • Using data for new types.
  •   
  • Using type to declare type synonyms, that is, alternative names for already existing types.
  •   
  • Using newtype to define new equivalent types to an existing one.
  •   

I recommend you read more about type declarations, since the type system is a fundamental part of Haskell. You can start with the Wikibook in Portuguese , where I took this reference.

    
09.04.2018 / 23:15