Why is the following Haskell script not working as expected?
find :: Eq a => a -> [(a,b)] -> [b] find kt = [v | (k,v) <- t]
Given find 'b' [('a',1),('b',2),('c',3),('b',4)]
, the interpreter returns [1,2,3,4]
instead of [2,4]
. To obtain this information, you must enter a new variable below u
:
find :: Eq a => a -> [(a,b)] -> [b] find kt = [v | (u,v) <- t, k == u]
Does anyone know why the first option does not give the desired result?
source share