Hi,
I'm sorry because I am absolutely sure, this is bloody obvious to the knowing. Being a total beginner I'm stuck. In the main = do part I wrote: 1: if a == True then putStrLn "Yes!" else putStrLn "No." 2: if a == True then let b = "+" else let b = "-" Line #1 works perfectly well. Read line #2 as pseudocode and you'll see what I want to do. Read it in ghci and it produces " parse error on input `=' " I tried 'case of' but it doesn't work either. What am I doing wrong? Thank you for any help, Bernhard |
Try this: let b = if a == True then "+" else "-" in ...
On Thu, Jun 25, 2009 at 4:12 PM, Bernhard Lehnert <[hidden email]> wrote: > Hi, > > I'm sorry because I am absolutely sure, this is bloody obvious to the > knowing. Being a total beginner I'm stuck. In the main = do part I > wrote: > > 1: if a == True then putStrLn "Yes!" else putStrLn "No." > 2: if a == True then let b = "+" else let b = "-" > > Line #1 works perfectly well. > Read line #2 as pseudocode and you'll see what I want to do. Read it in > ghci and it produces > " parse error on input `=' " > > I tried 'case of' but it doesn't work either. > > What am I doing wrong? > Thank you for any help, > > Bernhard > > > > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://www.haskell.org/mailman/listinfo/beginners > An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090625/d8143aa9/attachment.html |
In reply to this post by Bernhard Lehnert
On Jun 25, 2009, at 1:12 PM, Bernhard Lehnert wrote:
> 1: if a == True then putStrLn "Yes!" else putStrLn "No." > 2: if a == True then let b = "+" else let b = "-" You can try: let b = if a == True then "+" else "-" Also, whenever you find yourself testing 'x == True' or 'x == False', you can reduce that to 'x' and 'not x' respectively, so you go down to: let b = if a then "+" else "-" Hope that helps. -johnnnnnnn |
In reply to this post by Andrew Wagner
Andrew Wagner <wagner.andrew <at> gmail.com> writes:
> Try this: let b = if a == True then "+" else "-" in ... Or like this: main = do let b = if True then "a" else "b" putStrLn b -- Gracjan |
In reply to this post by Bernhard Lehnert
> Since ifs are an expression in haskell, they return a value, All right, that explains it. Today I learned to think of that expression thing even in do blocks. Thank you to everyone! Cheers, Bernhard |
In reply to this post by Bernhard Lehnert
Am Donnerstag 25 Juni 2009 22:12:08 schrieb Bernhard Lehnert:
> Hi, > > I'm sorry because I am absolutely sure, this is bloody obvious to the > knowing. Being a total beginner I'm stuck. In the main = do part I > wrote: > > 1: if a == True then putStrLn "Yes!" else putStrLn "No." > 2: if a == True then let b = "+" else let b = "-" > > Line #1 works perfectly well. > Read line #2 as pseudocode and you'll see what I want to do. Read it in > ghci and it produces > " parse error on input `=' " > > I tried 'case of' but it doesn't work either. > > What am I doing wrong? > Thank you for any help, > > Bernhard > let b = "+" is not a complete expression, thus cannot be a branch of 'if'. It should give a parse error on 'else' (and my ghci does). But (putStrLn "Yes!") is a complete expression, so can be used as a branch of an if- expression. You probably want to bind the name b to a value depending on a somewhere in main's do- block? That would be achieved so: let b = if a then "+" else "-" b can then be used in following statements. Outside of a do-block, you would have to write let b = if a then "+" else "-" in someExpression HTH, Daniel |
In reply to this post by Andrew Wagner
Andrew Wagner wrote:
> Try this: let b = if a == True then "+" else "-" in ... The little figurine of Dijkstra in my head is urging me to write this as let b = if a then "+" else "-" in ... instead. ;) Regards, apfelmus -- http://apfelmus.nfshost.com |
Well sure. I was assuming it was a simplified example...
On Fri, Jun 26, 2009 at 7:30 AM, Heinrich Apfelmus < [hidden email]> wrote: > Andrew Wagner wrote: > > Try this: let b = if a == True then "+" else "-" in ... > > The little figurine of Dijkstra in my head is urging me to write this as > > let b = if a then "+" else "-" in ... > > instead. ;) > > > Regards, > apfelmus > > -- > http://apfelmus.nfshost.com > > _______________________________________________ > Beginners mailing list > [hidden email] > http://www.haskell.org/mailman/listinfo/beginners > An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090626/5e73562a/attachment.html |
Free forum by Nabble | Edit this page |