Thanks a lot chi, it works perfectly. I just made a new function:
describePaths situacio edges = case lookup situacio edges of Nothing -> [] Just locs -> map describePath locs
.. and works pretty well:
*TextGame> situacio = "living-room"*TextGame> describePaths situacio edges["There is door going west from here.","There is ladder going upstairs from here."]
But I see that I do not fully understand the <$> operator. I follow the comments of : What does <$> mean in Haskell?
So I follow the suggestion : https://hoogle.haskell.org/?hoogle=%3C$%3E
This is call a Functor:
(<$>) :: Functor f => (a->b) -> f a -> f b
That actually is exactly the same as fmap:
fmap :: Functor f => (a -> b) -> f a -> f b
It seems that are the same:
*TextGame> (*2) <$> [1..3][2,4,6]*TextGame> fmap (*2) [1..3][2,4,6]
But, actually they are different:
*TextGame> map describePath <$> lookup situacio edgesJust ["There is door going west from here.","There is ladder going upstairs from here."]*TextGame> fmap (describePath) (lookup situacio edges)<interactive>:30:22: error:• Couldn't match type ‘[Lloc]’ with ‘Lloc’ Expected type: Maybe Lloc Actual type: Maybe [Lloc] ....
Could someone put a little more light on it ? I do not fully understand why 'fmap (describePath) (lookup situacio edges)' do not work?(I am playing with Maybe's and Just's but ...)