How to define Haskell datatype range use Enum

  • A+
Category:Languages

I define my own datatype.

data Row = A | B | C deriving (Show,Eq,Ord) 

The question is, if there is a more elegant way to define my range than this?

instance Ix Row where
range (A,A) = [A]
range (A,B) = [A,B]
range (A,C) = [A,B,C]
range (B,B) = [B]
range (B,C) = [B,C]
range (C,C) = [C]
range _ = []


There is: Derive Enum and define

range (x, y) = [x .. y] 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: