Re: Flexible Enumerations

From: Michael Hanus <mh_at_informatik.uni-kiel.de>
Date: Thu, 09 Dec 2004 12:51:40 +0100

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.

Best regards,

Michael

_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Thu Dec 09 2004 - 13:07:41 CET

This archive was generated by hypermail 2.3.0 : Wed Sep 18 2019 - 07:15:05 CEST