views:

86

answers:

2

Hi,

I was using Moscow ML to work through the exercises in PFD till I hit chapter on Lazy Evaluation. Mosml implementation does not have any thing like $ notation described in the book. Mosml comes with suspension datatype but I cannot use pattern matching as described in the book.

Which implementation of ML did you use to work though PFD?

Thanks

+2  A: 

The $ notation is his own notation and I don't think there is an implementation that matches that exactly. You can create a variant type around the susp module in Moscow ML though, if that helps. I program in ocaml, so I lied, I'm not sure if you can, but being an ML flavor, I imagine the possibility almost certainly. So, something like this, in ocaml:

type 'a mylazy = 
    | Lazy of 'a Lazy.t
    | Eager of 'a

This additional construct shouldn't affect the memoization that Lazy gives you in casual use. But, if you are using lazy values you don't usually worry about the Eager case and only have a lazy case utilizing the memoization that the modules provide, forcing the value each time without subsequent penalties.

(also, I used OCAML to work through Purely Functional Data Structures)

nlucaroni
+1  A: 

As far as I can see from the introduction he gives of the $-notation, it is simply his own, introduced for sake of keeping the code in his thesis cleaner.

He also notes that "(The susp) primitives are sufficient to encode all the algorithms in this thesis."

Sebastian P.