From: "Chris Rathman" <[EMAIL PROTECTED]>
>
>     val it : unit = ()
>     ### evaluating file /alice/dict2.aml
>     def.aml:60.25-60.43: mismatch on application: expression type
>        ''26 * (key1type, (key2type, valtype ref) dictionary ref)
> dictionary
>     does not match function's argument type
>        ''26 * (''26, '27) dictionary
>     because type
>        ''26
>     does not unify with
>        key1type
>
> I'm not sure why a generic type ("26) wouldn't match the specific 
> key1type?


Note the double prime in the inferred type - it means that it is an equality 
type. Since you didn't specify key1type as an eqtype it cannot be unified 
with it.

The problem is that you compare "key = k" in function assoc. Hence your key 
types must support equality. Alternatively, you can pass your own eq 
functions as an additional functor parameters and call those (or take an 
ordering right away to avoid the linear searches).

Btw, I feel your implementation is vastly more complicated than it needs to 
be. For fun I simplified it to what you can find below, maybe you find it 
useful.

- Andreas


signature DICTIONARY2_TYPES =
sig
    eqtype key1
    eqtype key2
    type value
end

signature DICTIONARY2 =
sig
    include DICTIONARY2_TYPES
    val get : key1 * key2 -> value option
    val put : key1 * key2 * value -> unit
end

functor Dictionary2 (Types : DICTIONARY2_TYPES) : DICTIONARY2 =
struct
    open Types

    (*) type ('a,'b) dictionary = ('a * 'b) list ref

    fun assoc (key, xs) =
        Option.map #2 (List.find (fn (k,x) => k = key) (!xs))

    fun assocIns (key, xs, default) =
        case assoc (key, xs) of
          | SOME x => x
          | NONE => (xs := (key, default) :: !xs; default)

    val table = ref nil

    fun get (k1, k2) =
        case assoc (k1, table) of
          | NONE => NONE
          | SOME table2 => Option.map ! (assoc (k2, table2))

    fun put (k1, k2, x) =
        assocIns (k2, assocIns (k1, table, ref nil), ref x) := x
end


_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users

Reply via email to