To add to what the other guys have said, I&#39;d like to comment on style..<div><br></div><div>re 1 (disp_pref), it&#39;s much more compositional to split that function into two parts:</div><div><br></div><div>the pure part: showPrefs = unlines . map show $ pref</div>
<div>and the non pure part: putStrLn</div><div><br></div><div>The reason that this is better is that a future function can manipulate the String that showPrefs produces – it can append, it can drop characters from it, it can reverse it, etc... This is not true of what is left over after the action of printing the string has happened.</div>
<div><br></div><div>It lets you reuse that function *much* more.</div><div><br></div><div>Bob<br><br><div class="gmail_quote">On Sun, Dec 27, 2009 at 1:42 PM, legajid <span dir="ltr">&lt;<a href="mailto:legajid@free.fr">legajid@free.fr</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br>
<br>
I have some trouble evaluating Enum class.<br>
Following is my source:<br>
<br>
data Authors= Buzzati | Werber | Verne | Ray | Asimov | Voltaire deriving (Enum, Show)<br>
<br>
auths=[Buzzati .. Verne] ++ enumFrom Ray<br>
pref=take 3 auths<br>
-- 1 disp_pref=mapM_ (putStrLn) pref<br>
<br>
auth1 = Buzzati<br>
auth2 = succ auth1       -- Werber<br>
auth3 = pred Asimov      -- Ray<br>
num_auth4=fromEnum Verne -- 2<br>
-- 2 toEnum<br>
<br>
main= display Buzzati<br>
display x = do<br>
       putStrLn (show x)<br>
       display (succ x)<br>
-- 3 end of enum<br>
<br>
1. could&#39;nt match expected type [Char] against inferred type Authors<br>
I would like to display each data constructor name on one line , giving :<br>
Buzzati<br>
Werber<br>
Verne<br>
How can i translate data from one type to another (Authors to [Char])?<br>
<br>
2. Like fromEnum gives data constructor index, is it possible with toEnum (or other way) to get the nth constructor of the given type ?<br>
eg : 2 applied to Authors (not in scope ?) would give Verne<br>
<br>
3. tried to take  &#39;succ&#39; of last tag  in  enumeration<br>
How to detect the end of an enumeration ? Can i get the maxbound index ?<br>
<br>
Thanks,<br>
Didier.<br>
<br>
<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>