Semicolon value in lambda expression

A type:

data Command a = Command String (a -> IO a) 

      

Function:

iofunc_ :: String -> (a -> IO ()) -> Command a
iofunc_ s f = Command s (\x -> do f x ; return x)

      

What does a semicolon do in a lambda expression (\x -> do f x ; return x)

?

+3


source to share


2 answers


They just separate the two expressions f x

and return x

in notation. In fact, they are all equivalent in your case:



iofunc_ s f = Command s (\x -> do f x ; return x)

iofunc_ s f = Command s (\x -> do {f x ; return x})

iofunc_ s f = Command s (\x -> do f x
                                  return x)

iofunc_ s f = Command s (\x -> f x >> return x)

      

+8


source


A semicolon anywhere is equivalent to changing the indented line at the same level as the previous valid expression.



I saw this while looking at how indentation works ( https://en.wikibooks.org/wiki/Haskell/Indentation ).

+1


source







All Articles