Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. IO operations (Alexander Chen) 2. Re: IO operations (Francesco Ariis) 3. Re: IO operations (Alexander Klink) 4. Re: IO operations (Tobias Brandt) ---------------------------------------------------------------------- Message: 1 Date: Thu, 13 Aug 2020 13:02:19 +0200 (CEST) From: Alexander Chen <alexan...@chenjia.nl> To: beginners@haskell.org Subject: [Haskell-beginners] IO operations Message-ID: <252977439.222507.1597316539...@ichabod.co-bxl> Content-Type: text/plain; charset="utf-8" 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! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200813/af2c8f4c/attachment-0001.html> ------------------------------ Message: 2 Date: Thu, 13 Aug 2020 13:19:26 +0200 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] IO operations Message-ID: <20200813111926.GC2065@extensa> Content-Type: text/plain; charset=utf-8 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 ------------------------------ Message: 3 Date: Thu, 13 Aug 2020 13:24:00 +0200 From: Alexander Klink <alexan...@klink.name> To: Alexander Chen <alexan...@chenjia.nl>, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] IO operations Message-ID: <20200813112400.gn20...@putna.0x90.eu> Content-Type: text/plain; charset=iso-8859-1 On Thu, Aug 13, 2020 at 01:02:19PM +0200, Alexander Chen wrote: > 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? dict is of type String, since it's a String containing the complete file. That's why the type complaint is that you want to check if '-' (a Char) is an element of x, which is also a Char, which cannot work. I asssume what you want is a list of lines, which you can by applying the lines function, e.g. here: return $ length [x | x <- lines dict , not $ '-' `elem` x] HTH, Cheers, Alex ------------------------------ Message: 4 Date: Thu, 13 Aug 2020 13:14:39 +0200 From: Tobias Brandt <to...@uni-bremen.de> To: beginners@haskell.org Subject: Re: [Haskell-beginners] IO operations Message-ID: <778b310a-184c-f604-491d-7e74bb3de...@uni-bremen.de> Content-Type: text/plain; charset="utf-8"; Format="flowed" 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@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-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 146, Issue 4 *****************************************