[mercury-users] My MSc thesis project implemented in Mercury

Peter Hawkins hawkinsp at cs.stanford.edu
Thu Jan 3 11:56:24 AEDT 2008


Hi...

Just a comment on Section 6.1.1 on the difficulty of writing
non-deterministic code in ML:

"In this way, one could implement a behaviour that is a substitute for
nondeterminism, using exception throwing for backtracking. I have
followed that path, however at some point the code became very
complicated. When I realized that I'm using lists of lists of lists,
I have decided that I need a language with support for nondeter-
minism, so I have dropped the StandardML as an implementation
language."

You can do this in a not entirely painful way in Haskell or OCaml by
using monads [1].

e.g. in OCaml with the appropriate extension you can do this:
module ListMonad = struct
  type 'a t = 'a list
  let bind lst f = List.concat (List.map f lst)
  let return x = [ x ]
  let failwith s = []
end

let make_pairs (xs:'a ListMonad.t) (ys:'b ListMonad.t) : ('a * 'b) ListMonad.t =
   perform with module ListMonad in (
     x <-- xs;
     y <-- ys;
     ListMonad.return (x, y)
   )

then you can write:
make_pairs [1,2] ["a", "b"]
and get
[(1,"a"), (1, "b"), (2, "a"), (2, "b")]

It isn't quite a logic programming language, but it sure can make your
life nicer. Of course, if you're doing this sort of thing a lot
Mercury is probably a better choice.

Peter

[1] Monads in Ocaml, you ask? See the pa_monad extension to OCaml
which adds Haskell-like syntactic sugar for monads.

On Jan 2, 2008 3:03 PM, Ralph Becket <rafe at csse.unimelb.edu.au> wrote:
> Bartlomiej Szymczak, Wednesday,  2 January 2008:
> > Interested Mercury users may have a look at my MSc thesis. I've chosen
> > Mercury as the implementation language. Chapter "Implementation" is
> > what you should look for, especially if you want to see how I've
> > managed to integrate Java Server Pages user interface with engine
> > written in Mercury. All the source code is of course visible in the
> > appendices.
>
> It's great to have another happy customer!
>
> --------------------------------------------------------------------------
> mercury-users mailing list
> Post messages to:       mercury-users at csse.unimelb.edu.au
> Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
> Subscriptions:          mercury-users-request at csse.unimelb.edu.au
> --------------------------------------------------------------------------
>
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list