<div dir="ltr">Or rather, you can just say do { return something } or do { return $ something } of "something" is a more complicated expression.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Oct 23, 2015 at 10:16 AM Rein Henrichs <<a href="mailto:rein.henrichs@gmail.com">rein.henrichs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You can't transform an IO String into a String. This is one of the purposes of monads: to make it possible to work with things like IO, where it is impossible to turn an IO a into an a. The result of performing an IO action can be *bound* using (>>=) or <- in do notation so that the String is available for the rest of the computation:<div><br></div><div></div></div><div dir="ltr"><div><div>do</div><div> f <- readFile "ctrl.txt"</div></div></div><div dir="ltr"><div><div> Right r <- parseCtrl f</div><div> cherchectrl r "A01"</div></div><div><br></div><div>Note that there's no need to wrap identifiers in (): (r) is the same as r, (rez) is the same as rez. And there's no need to say do { let r = something; return r }. You can just say do { something }.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Oct 23, 2015 at 8:32 AM chanti houda <<a href="mailto:houdachanti@yahoo.fr" target="_blank">houdachanti@yahoo.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:times new roman,new york,times,serif;font-size:16px"><div dir="ltr">Hello, I'm writing a Haskell code which consists to read a text file, parse it and thansform the parsing result on a specific language.</div><div dir="ltr">I have a function <b>affiche </b>which takes a data type Ctrl and returns a String. This is the transformation funtion.</div><div dir="ltr">I have also anothe function parsctrl, which parse the c<span lang="en"><span>ontents of a text file ("ctrl.txt") and after looks for a specific value ("A01") in the parse result (function <b>c</b></span></span><b>herchectrl</b>). <br></div><div dir="ltr">I need to use the result of the <b>parsectrl </b>function in another function <b>fc</b>. <br></div><div dir="ltr">The code is composed of three functions <br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">parsectrl = do<br> f <- readFile "ctrl.txt"<br> let Right r = parse parseCtrl " " f</div><div dir="ltr"> let rez =cherchectrl ( r) "A01"<br> return (rez)</div><div dir="ltr"><br></div><div dir="ltr">fc[] =[] <br>fc((door,[(all,v1),(alt,v2),(lint,v3),(w,v4),(r,v5),(loc,v6),( etat,v7),(ruin,v8)]):ls ) = ("&OUV ID='"++door ++"', ALLEGE="++show((moi v1)/1000)++", LINTEAU="++show((moi v3)/1000)++", LARGEUR="++show((moi v4)/1000)++", COEF=0.7, ALT="++show((moi v2)/1000)++", LOCIDS='"++v6++"', CTRLID='"++ v7++"', CTRLID_RUIN='"++ v8++" /" ++"\n" ++"&CTRL ID='"++v7++"', " ++ "ON_INI=.FALSE., DURATION=0 / \n"++"&CTRL ID='"++v8++"', LOCID='"++ ((parses("'"++v6++"'"))!!0) ++<font color="#cd232c"><b>affiche(parsectrl)</b></font>++ " / \n\n" )++fc(ls)<br></div><div dir="ltr"><br></div><div dir="ltr">The parsectrl returns an IO String, but the function affiche needs a String as input and even when I tried to adapt the affiche function to take an IO String -> String I can't.</div><div dir="ltr">the result of fc must be a String too.</div><div dir="ltr"><br></div><div dir="ltr">The IO String comes from the parsectrl function.<br></div><div dir="ltr">Can you help me to solve this problem: how can I transform an IO String to a String.</div><div dir="ltr"><br></div><div dir="ltr">Thank you by advance.<br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><br><br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div></blockquote></div>