Tiago Loureiro
Tiago Loureiro

Reputation: 65

Haskell Data.Map Lookup not looking for all values

I'm trying to have one Map that maps [Char] to Complex Double.

But every time I make a lookup for certain elements of that map I don't get the result i'm expecting.

Example: searching "h" in [("h",1 ),("_c",1 :+ 1),("x",2 :+ 0),("y",5)]

*Main> lookup "h" (fromAscList [("h",1 ),("_c",1 :+ 1),("x",2 :+ 0),("y",5)])
Nothing

Example: searching "y" in [("h",1 ),("_c",1 :+ 1),("x",2 :+ 0),("y",5)]

*Main> lookup "y" (fromAscList [("h",1 ),("_c",1 :+ 1),("x",2 :+ 0),("y",5)])
Just (5.0 :+ 0.0)

I'm getting a weird behaviour from this structure.

Would be much apreciated for an answer.

Upvotes: 3

Views: 648

Answers (1)

kraskevich
kraskevich

Reputation: 18566

The fromAscList function should be applied to an ascending list. But "h" > "_c". Your code violates this precondition, so it is not a surpruse that it does not work properly.

Upvotes: 8

Related Questions