[Haskell-beginners] In Search Of a clue... (Defining and making use of a type)

Adrien Haxaire adrien at haxaire.org
Tue Dec 13 09:13:30 CET 2011


 Hello,

 If you define your constructor like this:
> data  ScrConfig = ScrConfig [ ScrUple ]  deriving (Show)

 it means that you need to give a list to the data constructor 
 ScrConfig. It will then return the type ScrConfig, which is what you 
 want. In GHCi:

 Main*>:t ScrConfig
 ScrConfig :: [ScrUple] -> ScrConfig

 This means that you do not have to declare sc1 as type ScrConfig, it is 
 inferred by the compiler.
 So the declaration :

> ScrConfig sc1 =ScrConfig( [s2 s1] ) ;

 should be:

 sc1 =ScrConfig( [s2 s1] ) ;

 The second point is that you do not give a list to ScrConfig, as list 
 elements are separated with a comma in Haskell: [s2, s1]. So sc1 
 becomes:

 sc1 =ScrConfig( [s2, s1] ) ;

 and this will fix your first error.

 By the way, you do not need to add parens around the list, nor a 
 semicolon at the end of the line. They do no harm here, but I find it 
 clearer without. So I would write sc1 like this:

 sc1 = ScrConfig [s2, s1]


 Hope that helps,
 Adrien



More information about the Beginners mailing list