[MLton-user] Re: More Extended Basis Library

Geoffrey Alan Washburn geoffw at cis.upenn.edu
Sun Mar 4 12:08:12 PST 2007


Vesa Karvonen wrote:
> Like I said, I'm not sure that I understand the idea.  Let's say that a
> type (module defining the type) would implement both HAS_PRODUCTS and
> HAS_UNIT.  Would this mean that it has constructors with the types
>
>  t * t -> t
>
> and
>
>  unit -> t
>
> An example of such a datatype would be, for example,
>
>  datatype t = PRODUCT of t * t | UNIT .
>
> IOW, the idea is that one would specify the structure of a datatype using
> the signatures.  If this is roughly the idea, then I think that one or
> more of the ways of encoding type-indexed values might be more practical.
> See, for example,
    I am thinking about it more categorically/algebraically, rather than 
for specifying the structure of the datatype.  Here are perhaps what I 
would consider the minimal signatures for »HAS_PRODUCTS« and »HAS_UNIT«

    signature HAS_PRODUCTS = sig
       type t
       val formProduct : t * t -> t
       val isProduct : t -> bool
       val fst : t -> t Option.t
       val snd : t -> t Option.t
    end

    signature HAS_UNIT = sig
       type t
       val formUnit : unit -> t
       val isUnit : t -> bool
    end

Then one could provide implementations of »HAS_PRODUCTS« and »HAS_UNIT« 
for any number of things, such as lists, sets, prime integers, etc. that 
implements some notion of products and units on that data type. For sets 
one could use the empty set as the unit, and the Cartesian product on 
sets as the product operation.  For prime integers one could use 
multiplication as the product and 1 as the unit.  However, it would 
probably be useful to also supply a type-indexed version

    signature HAS_PRODUCTS' = sig
       type 'a t
       val formProduct : 'a t * 'b t -> ('a, 'b) Pair.t t
       val isProduct : 'a t -> bool
       val fst : ('a, 'b) Pair.t t -> 'a t
       val snd : ('a, 'b) Pair.t t -> 'b t
    end

    signature HAS_UNIT' = sig
       type 'a t
       val formUnit : unit -> unit t
       val isUnit : 'a t -> bool
    end

I suppose it is arguable that these are too abstract to be useful as 
part of the extended basis.

-- 
[Geoff Washburn|geoffw at cis.upenn.edu|http://www.cis.upenn.edu/~geoffw/]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mlton.org/pipermail/mlton-user/attachments/20070304/74206a98/attachment.html


More information about the MLton-user mailing list