[Haskell-beginners] IO operations
Tobias Brandt
to_br at uni-bremen.de
Thu Aug 13 11:14:39 UTC 2020
Hey Alexander,
|dict| has type |String|. Therefore, |x| is of type |Char|, but |elem
'-'| is of type |[Char] -> Bool| (simplified). Hence, you get a type
mismatch. If you just want to count every character except |'-'|, then
you could just you |'-' /= x|.
Cheers
Tobias
On 8/13/20 1:02 PM, Alexander Chen wrote:
> Hi,
>
> module Main where
> allwords :: IO Int
> allwords = do
> dict <- readFile "data/dict.txt"
> return $ length [x | x <- dict , not $ '-' `elem` x]
> main :: IO Int
> main = do allwords
>
> error
>
> * Couldn't match expected type `t0 Char' with actual type `Char'
> * In the second argument of `elem', namely `x'
> In the second argument of `($)', namely '-' `elem` x
> In the expression: not $ '-' `elem` x
>
>
> could someone tell me what I am doing wrong?
>
> thanks!
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200813/98839a35/attachment.html>
More information about the Beginners
mailing list