[Haskell-beginners] IO operations

Francesco Ariis fa-ml at ariis.it
Thu Aug 13 11:19:26 UTC 2020


Hello Alexander

Il 13 agosto 2020 alle 13:02 Alexander Chen ha scritto:
> allwords :: IO Int
> allwords  = do
>     dict <- readFile "data/dict.txt"
>     return  $ length [x | x <- dict , not $ '-' `elem` x]

`elem` has type:

    λ> :t elem
    elem :: Eq a => a -> [a] -> Bool
    -- almost

You are comparing '-' (a `Char`) with `x` (another `Char`), hence you
only need `==`. Does this make sense?
—F


More information about the Beginners mailing list