[PL-sem-jr] Notes on PLJunior Dec 12, 2018

Julia Belyakova julbinb at gmail.com
Wed Dec 12 17:49:15 EST 2018


Hi all,

Today we have gone through pages 6-10 of the Awkward Squad paper (we
finished section 2.5).
We are going to meet next Monday at the usual time.

We discussed "bind" (>>=) and "then" (>>) functions.
We noticed that "bind" is very CPS-ish, and also similar to ".then" in
JavaScript.  It makes an order of evaluation explicit:

thing1 >>= \x -> thing2

means that thing1 happens first, its result is bind to x, and then thing2
happens.

"Then" operator ("thing1 >> thing2") is like sequencing using ";" in ML
("thing1 ; thing2"). It is similar to bind (and is implemented using bind),
but the result of thing1 does not matter — it is thrown away.

Function "return" is needed to put pure values into monadic contexts, in
particular, into IO (page 6). The analogy of "return" in the div-by-0
exercise was the constructor "Ok".

The putLine function (page 7) can be implemented as:

putLine :: [Char] -> IO ()
putLine [] = return ()
putLine (c : cs) =
    putChar c >>
    putLine cs

Section 2.3 discusses do-notation, which makes code more imperative-like.
Basically, it allows us to write

x <- action

instead of

action >>= \x ->

With do-notation we can implement the last case of putLine as

putLine (c : cs) = do { putChar c ; putLine cs }

In the middle of page 7 there is a discussion about "<-" being binding, not
assignment (in "c <- thing1 ;  c <- thing2" the two "c" are not the same
location). We noticed that this is just shadowing (like in "let c = thing1
in let c = thing2").

--
Kind regards, Julia
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the Pl-sem-jr mailing list