[Haskell] How to implement A-lists and P-lists in Haskell (cont.)

Tom Jordan viresh53 at gmail.com
Wed May 26 16:35:17 EDT 2010


Sorry that I couldn't respond to the previous thread.. I'm using Gmail and
not an email client so I couldn't use the reply button. I'll try to resolve
this issue soon !

Thanks Phillip for responding so quickly,

I tried Data.Map first and ran into the issue you mentioned..

I've found a way to get around it, but it's ugly and verbose..

Instead, I'm wondering if there is a way to use the constructors for the
"Val" types below, in place of the keys such as:

data Val = Root Root | Oct Oct | Mode Mode deriving (Show, Eq, Ord)

And matching against the constructors, instead of resorting to this:


import IO
import qualified Data.Map as Map

type Root = String
type Oct  = Integer
type Mode = Integer

data Key = Root | Oct | Mode deriving (Show, Eq, Ord)
data Val = Root_v Root | Oct_v Oct | Mode_v Mode deriving (Show, Eq, Ord)

test = Map.insert Oct (Oct_v 3) . Map.insert Mode (Mode_v 0) . Map.insert
Root (Root_v "2") $ Map.empty

main = print test

--  ---->  fromList [(Root,Root_v "2"),(Oct,Oct_v 3),(Mode,Mode_v 0)]


Many Thanks,

Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell/attachments/20100526/9f483614/attachment.html


More information about the Haskell mailing list