Re: higher-order functors
Geoffrey Alan Washburn <[email protected]> Sat, 24 Mar 2007 11:44:14 -0400
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
Dave Herman wrote:
> At this point I was stabbing in the dark, but I tried moving the
> where-clause instead to the declaration of MK_COROUTINE:
>
> funsig MK_COROUTINE (type result) = COROUTINE
> where type result = result
>
> But then I got the compiler error:
>
> Error: Compiler bug: LtyExtern: wrong TCs in tc_select
>
> I
>
As another data-point, I just encountered the same error while
attempting to use higher-order functors. In my case, the
example below compiles fine if I remove the definition of "add'".
Alternately, I discovered that rewriting it as
fun add' (x, b) = add (b, x)
also compiles fine. eta-reducing the definition below to
val add' = add o swap
doesn't fix the problem. I'm using 110.62, with patches to the parser,
but the problem also occurs when I tried an unpatched build of 110.54.
functor Bag (functor Map(K : ORD_KEY) : ORD_MAP) (K : ORD_KEY) = struct
structure Key = K
structure BM : ORD_MAP = Map (K)
type item = BM.Key.ord_key
type bag = word BM.map
type t = bag
val empty : bag = BM.empty
fun singleton (x : item) = BM.singleton (x, 0w1)
fun add (b : bag, x : item) =
(case BM.find (b, x)
of SOME n => BM.insert (b, x, n + 0w1 )
| NONE => BM.insert (b, x, 0w1))
fun swap (x, y) = (y, x)
fun add' x = (add o swap) x
(* ... other operations not yet implemented ... *)
end
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV