Hacking for great justice!

I just finished hacking the SML/NJ parser to allow monad comprehension sugar. Here is an example of using it when using the list monad.

  1. - infix 5 >>=;
  2. infix 5 >>=
  3. - [| x | x <~ [1,2,3] |];
  4. val it = [1,2,3] : int list
  5. - [| (x, y) | x <~ [1,2], y <~ ["a", "b"] |];
  6. val it = [(1,"a"),(1,"b"),(2,"a"),(2,"b")] : (int * string) list
  7. -

I first looked at adding »do« notation, but that would have been kind of ugly without the offside rule. The only disadvantage to using comprehension syntax is that you must always »return« something. However, I expect that will be reasonable enough for my work on InforML. Additionally I had original chosen to use <- instead of <~, but it was already taken in some user defined code somewhere in the SML basis. I also determined that the source of my mysterious parsing behavior in InforML was being caused by a few small instances of backtracking in my grammar. However, I still can't see how backtracking was causing the problem. In any event, I was lucky and discovered that the backtracking was no longer necessary in the grammar and all is well.

2 Comments »

  1. kitby said,

    December 23, 2006 @ 5:58 pm

    What’s the “offside” rule? (Makes me think of a soccer game.)

  2. washburn said,

    December 23, 2006 @ 6:59 pm

    See Offside rule on Wikipedia.

RSS feed for comments on this post · TrackBack URI

Leave a Comment