From e6d58cce0594f709fbb4cad79ee8986c190c2e3f Mon Sep 17 00:00:00 2001 From: jim Date: Mon, 6 Apr 2015 05:11:34 -0400 Subject: [PATCH] add link to rosetta --- topics/week8_monads_and_modules.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topics/week8_monads_and_modules.mdwn b/topics/week8_monads_and_modules.mdwn index 49835583..979892d7 100644 --- a/topics/week8_monads_and_modules.mdwn +++ b/topics/week8_monads_and_modules.mdwn @@ -551,7 +551,7 @@ These mostly have to be entered as individual lines in the interactive interpret There remains a final major Monad, the Continuation monad, that we'll discuss and add to the library later. -We'll discuss the different `ask, shift, pick`, and so on functions [[on another page|/topics/week9_using_the_monad_library/]]. But just to give some examples, in the List monad, `mzero` corresponds to `[]` and `++` as we mentioned before corresponds to `List.append`, which OCaml also writes as the infix operator `@`. For some reason I don't like that operator, so I mostly avoid it. Maybe I don't like it because Haskell uses it with a different meaning. In Haskell, var @ pat is what OCaml writes as pat as var. (Discussed in Rosetta1. TODO LINK) So I tend to write instead just `List.append`. But when working with Lists as abstract monadic values, in OCaml, you need to use `++` instead of `List.append`. OCaml will act like it doesn't know that abstract monadic Lists are really `list`s. `test` takes a predicate of plain (non-monadic) lists, and if the monadic list that is its second argument satisfies it, returns that list unchanged, else returns `mzero` (the abstract list version of `[]`). `guard` takes a boolean argument, and if it's true returns `[()]` (as an abstract list) else returns `mzero`. These correspond to the Haskell operations of the same name. +We'll discuss the different `ask, shift, pick`, and so on functions [[on another page|/topics/week9_using_the_monad_library/]]. But just to give some examples, in the List monad, `mzero` corresponds to `[]` and `++` as we mentioned before corresponds to `List.append`, which OCaml also writes as the infix operator `@`. For some reason I don't like that operator, so I mostly avoid it. Maybe I don't like it because Haskell uses it with a different meaning. In Haskell, var @ pat is what OCaml writes as pat as var. (Discussed on our [[Rosetta1 page|/topics/week1_kapulet_advanced/#as-patterns]]) So I tend to write instead just `List.append`. But when working with Lists as abstract monadic values, in OCaml, you need to use `++` instead of `List.append`. OCaml will act like it doesn't know that abstract monadic Lists are really `list`s. `test` takes a predicate of plain (non-monadic) lists, and if the monadic list that is its second argument satisfies it, returns that list unchanged, else returns `mzero` (the abstract list version of `[]`). `guard` takes a boolean argument, and if it's true returns `[()]` (as an abstract list) else returns `mzero`. These correspond to the Haskell operations of the same name. Here is an example of using the List monad. -- 2.11.0