Re[2]: Flexible Enumerations

From: . <aik_at_fryazino.net>
Date: Thu, 9 Dec 2004 19:34:54 +0300

>> 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 ?

MH> There is a simple solution to get all solutions of an enumeration
MH> type. If you define a "member" constraint

MH> member x (y:ys) = x=:=y ? member x ys

MH> then you can get "Color" solutions by

MH> color x = member x [Red,Green]
You're right, but for each Enum type I have to define it's own member
function. I thought about auto-member function, e.g. when I define
Color type, Curry invents Color_member function. Just a bit of
syntactic sugar. Of course, I'm not sure whether this feature really
useful for real-world applications.

Thank you for attention,

      Igor
Received on Thu Dec 09 2004 - 18:09:04 CET

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