fork download
  1. find xs f = filter f xs
  2.  
  3. data Foo = Foo { key, value :: Int }
  4.  
  5.  
  6.  
  7. main = do
  8. let foo = [Foo 2 1, Foo 1 2, Foo 5 3]
  9. let range1 = find foo $ (== 1) . key
  10. let range2 = find foo $ \x -> key x == 1
  11. let range3 = [ x | x <- foo, key x == 1 ]
  12. mapM_ writefln [range1, range2, range3]
  13. where
  14. writefln xs = putStrLn $ "value for key 1 is " ++ show (value $ head xs)
Success #stdin #stdout 0s 6264KB
stdin
Standard input is empty
stdout
value for key 1 is 2
value for key 1 is 2
value for key 1 is 2