[Haskell-beginners] Case Expressions

Nathan Holden nathanmholden at gmail.com
Thu May 28 17:53:43 EDT 2009


I've been playing with my musical interval problem from before, and I got a
little further, but I came up with a problem.

I have two types-- Interval and BasicInterval.

Interval has 12 constructors, Unison, MinorSecond, MajorSecond, MinorThird,
et cetera.
BasicInterval has 8 constructors, BasicUnison, Second, Third, Fourth, and so
on.

I want to be able to convert between them somewhat;

I have function interToBasic, which at the moment looks like:

interToBasic :: Interval -> BasicInterval
interToBasic a = if (b == 1 || b == 2) then Second
                          else if (b == 3 || b == 4) then Third
..
where b = fromEnum a

What I wanted to do, and figure is probably doable, but I can't seem to find
it, is to say something like

case (fromEnum a) of
   1 || 2 -> Second
   3 || 4 -> Third
..

Is this doable? If so, what's the syntax?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090528/02601f12/attachment.html


More information about the Beginners mailing list