[Haskell-beginners] Enumerated types
legajid
legajid at free.fr
Sun Dec 27 08:42:48 EST 2009
Hello,
I have some trouble evaluating Enum class.
Following is my source:
data Authors= Buzzati | Werber | Verne | Ray | Asimov | Voltaire
deriving (Enum, Show)
auths=[Buzzati .. Verne] ++ enumFrom Ray
pref=take 3 auths
-- 1 disp_pref=mapM_ (putStrLn) pref
auth1 = Buzzati
auth2 = succ auth1 -- Werber
auth3 = pred Asimov -- Ray
num_auth4=fromEnum Verne -- 2
-- 2 toEnum
main= display Buzzati
display x = do
putStrLn (show x)
display (succ x)
-- 3 end of enum
1. could'nt match expected type [Char] against inferred type Authors
I would like to display each data constructor name on one line , giving :
Buzzati
Werber
Verne
How can i translate data from one type to another (Authors to [Char])?
2. Like fromEnum gives data constructor index, is it possible with
toEnum (or other way) to get the nth constructor of the given type ?
eg : 2 applied to Authors (not in scope ?) would give Verne
3. tried to take 'succ' of last tag in enumeration
How to detect the end of an enumeration ? Can i get the maxbound index ?
Thanks,
Didier.
More information about the Beginners
mailing list