Michael Hanus wrote:
> Igor wrote:
> > When I tried to write my first program in Curry, I've stumbled over
> > strange effect: MCC can not evaluate
> > data Color = Red | Green
> > x::Color
> > (x==Green) =:= False
> > although it seems obvious that x of type Color can be either Red or
> > Green.
> >
> > Is it possible to augment Curry with syntactic feature similar to
> > "deriving" - when I define "augmented" Enum type, Curry automatically
> > "forks" on each variable of that type to detect all applicable
> > solutions ?
>
> There is a simple solution to get all solutions of an enumeration
> type. If you define a "member" constraint
>
> member x (y:ys) = x=:=y ? member x ys
>
> then you can get "Color" solutions by
>
> color x = member x [Red,Green]
>
> Now just add the color constraint to your initial goal
>
> color x & (x==Green) =:= False
>
> and you'll get the solution Red.
>
> Although this approach requires the addition of a member call to such goals,
> I think the necessary code is so short that an additional syntactic
> feature seems not necessary until there are many applications
> where this is needed.
There is another simple solution.
data Color = Red | Green
Color = Red ? Green
x=:=Color & (x==Green) =:= False
It is interesting the parallel between the type Color and the
operation Color and the declaration of x's type, x::Color, and x's
constraint, x=:=Color.
Operation and constraint can be automatically generated and in
principle no syntactic sugar seems necessary... just a fancier
compiler front-end.
Sergio
_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Fr Dez 10 2004 - 09:28:18 CET