Discussion:
SML code generated from Isabelle: reference on code construction needed.
(too old to reply)
Bart Kastermans
2010-08-31 19:24:45 UTC
Permalink
The generated code is as follows. Function re_lit comes out exactly
as expected, except for its first argument. It was "supposed" to be
the function that checks if the list in its second argument starts
with the item in its first argument.

**********
structure re_lit : sig
type 'a eq
val eq : 'a eq -> 'a -> 'a -> bool
val eqa : 'a eq -> 'a -> 'a -> bool
val re_lit : 'a eq -> 'a -> 'a list -> (('a list * 'a list) list) option
end = struct

type 'a eq = {eq : 'a -> 'a -> bool};
val eq = #eq : 'a eq -> 'a -> 'a -> bool;

fun eqa A_ a b = eq A_ a b;

fun re_lit A_ x sigma =
(if eqa A_ (hd sigma) x then SOME [([x], tl sigma)] else NONE);

end; (*struct re_lit*)
*********

I do not understand the "type 'a eq" construction and how to use it.
Any references (or hints on how to google this) or of course
explanations would be greatly appreciated.

Best,
Bart
Phil Clayton
2010-09-04 13:38:24 UTC
Permalink
A good place to look for SML resources, including documentation, is on
the web sites of the SML interpreters/compilers. A list can be found
at
http://en.wikipedia.org/wiki/Standard_ML#Implementations

Although many links to material on university sites are now broken,
there is still plenty of information out there.

Phil
The generated code is as follows.  Function re_lit comes out exactly
as expected, except for its first argument.  It was "supposed" to be
the function that checks if the list in its second argument starts
with the item in its first argument.
**********
structure re_lit : sig
  type 'a eq
  val eq : 'a eq -> 'a -> 'a -> bool
  val eqa : 'a eq -> 'a -> 'a -> bool
  val re_lit : 'a eq -> 'a -> 'a list -> (('a list * 'a list) list) option
end = struct
type 'a eq = {eq : 'a -> 'a -> bool};
val eq = #eq : 'a eq -> 'a -> 'a -> bool;
fun eqa A_ a b = eq A_ a b;
fun re_lit A_ x sigma =
  (if eqa A_ (hd sigma) x then SOME [([x], tl sigma)] else NONE);
end; (*struct re_lit*)
*********
I do not understand the "type 'a eq" construction and how to use it.
Any references (or hints on how to google this) or of course
explanations would be greatly appreciated.
Best,
Bart
Florian Weimer
2010-09-08 17:02:57 UTC
Permalink
Post by Bart Kastermans
I do not understand the "type 'a eq" construction and how to use it.
This expresses the requirement that the type a must have a function
which (presumably) implements an equality check. You should be able
to supply fn _ => op= (the default equality operator) in most cases.

Usually, in SML, you use type variables such as ''a to express that
the actual type must admit the default equality operator, but this
will not work for other operators (such as arithmetic or comparison).
Torben Ægidius Mogensen
2010-09-09 08:08:08 UTC
Permalink
Post by Florian Weimer
Post by Bart Kastermans
I do not understand the "type 'a eq" construction and how to use it.
This expresses the requirement that the type a must have a function
which (presumably) implements an equality check. You should be able
to supply fn _ => op= (the default equality operator) in most cases.
Usually, in SML, you use type variables such as ''a to express that
the actual type must admit the default equality operator, but this
will not work for other operators (such as arithmetic or comparison).
Haskell introduced type classes to extend type constraints to require
arithmetic and so on. It even allows user-defined type constraints.
Type classes were originally just intended to handle overloading, but
are now used for generic programming as well.

Torben
Bart Kastermans
2010-09-10 16:50:34 UTC
Permalink
Thanks for the help and pointers. I should really look into Haskell
one of these days.

Best,
Bart

Loading...