FW: Do we need a mouse trap?

Nick Kallen nkallen@uclink4.berkeley.edu
Thu, 4 Mar 1999 03:51:13 -0800


> MNU1 (MENU nm entries) ids ps
> # (error, ps)= openMenu undef (mkM entries) ps
> | error <> NoError= closeProcess ps
> | otherwise= ps
> where
> { //mkM xs= Menu nm ( ListLS [MenuItem item []\\ item <- xs]) []
>   mkM xs= Menu nm (menuM xs) []
> ; menuM [x]= MenuItem x []
> ; menuM [x:xs]= (MenuItem x []) :+: (menuM xs)
> };
>
>
> If I try to compile this program, I get an error message, saying
> that "menuM" cannot unify demanded type MenuItem a b
> with :+: MenuItem MenuItem a b.

I unfortunately didn't have too long to look at this, but I did try a few
things:

I first looked at your code, recognized the foldr pattern, and tried to
write it that way:

menuM = foldr (\x -> (:+:) (MenuItem x [])) NilLS
// I assume that NilLS is the identity element for :+:

I got the following type error:

"foldr" cannot unify demanded type (a b c) with :+: MenuItem a b c

I think this is one of the things that HM simply barfs on. Since :+: doesn't
satisfy the closure property, weird stuff happens. You can certainly solve
this with dynamic types (where's clean 2.0?)... I can't think of a way (off
the top of my head) of how to do this now, however. I'd venture a guess that
might be impossible (is that vague enough?).