Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/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. Re: Improve my FFI code please... (Christian Maeder) 2. Re: Improve my FFI code please... (s...@objitsu.com) 3. Re: Improve my FFI code please... (Daniel Fischer) 4. Question about List Type Constraint and Null (aditya siram) 5. Re: Question about List Type Constraint and Null (Magnus Therning) ---------------------------------------------------------------------- Message: 1 Date: Fri, 21 Jan 2011 13:46:36 +0100 From: Christian Maeder <christian.mae...@dfki.de> Subject: Re: [Haskell-beginners] Improve my FFI code please... To: Sean Charles <s...@objitsu.com> Cc: beginners@haskell.org Message-ID: <4d39802c.5060...@dfki.de> Content-Type: text/plain; charset=ISO-8859-1 Am 21.01.2011 00:35, schrieb Sean Charles: > wiiClose :: Ptr Word8 -> IO Bool > wiiClose wptr = do > response <- c_wiimote_close wptr > case response of > 0 -> return True > _ -> return False This can be rewritten to: wiiClose = fmap (== 0) . c_wiimote_close > case status of > True -> putStrLn "OK" > False -> putStrLn "FAIL" Matching Bool values use "case" is no good style: putStrLn (if status then "OK" else "FAIL") Christian ------------------------------ Message: 2 Date: Fri, 21 Jan 2011 15:43:10 +0000 From: s...@objitsu.com Subject: Re: [Haskell-beginners] Improve my FFI code please... To: Christian Maeder <christian.mae...@dfki.de> Cc: beginners@haskell.org Message-ID: <20110121154310.48911ywp255yf...@abe.enixns.com> Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Quoting Christian Maeder <christian.mae...@dfki.de>: > Am 21.01.2011 00:35, schrieb Sean Charles: >> wiiClose :: Ptr Word8 -> IO Bool >> wiiClose wptr = do >> response <- c_wiimote_close wptr >> case response of >> 0 -> return True >> _ -> return False > > This can be rewritten to: > > wiiClose = fmap (== 0) . c_wiimote_close > >> case status of >> True -> putStrLn "OK" >> False -> putStrLn "FAIL" > > Matching Bool values use "case" is no good style: > > putStrLn (if status then "OK" else "FAIL") > > Christian > > That's clever but you'd have to *know* haskell to *know* you could do that! Point-free (pointless!) is something I have yet to fully tackle, it looks like a great thing. Function composition is something else for my brain to remember exists in the language! IIUC: given a Ptr8 Word, call c_wiimote close then 'functor map' the 'section' (== 0) over the single entry in the list... what list? I am confused again because I cannot see a list, c_wiimote_close answers a pointer. I understand (== 0) rather than (0 ==) though, that's something! Thanks for your time. :) ------------------------------ Message: 3 Date: Fri, 21 Jan 2011 16:58:19 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Improve my FFI code please... To: beginners@haskell.org Cc: s...@objitsu.com Message-ID: <201101211658.19687.daniel.is.fisc...@googlemail.com> Content-Type: text/plain; charset="iso-8859-1" On Friday 21 January 2011 16:43:10, s...@objitsu.com wrote: > Quoting Christian Maeder <christian.mae...@dfki.de>: > > Am 21.01.2011 00:35, schrieb Sean Charles: > >> wiiClose :: Ptr Word8 -> IO Bool > >> wiiClose wptr = do > >> response <- c_wiimote_close wptr > >> case response of > >> 0 -> return True > >> _ -> return False > > > > This can be rewritten to: > > > > wiiClose = fmap (== 0) . c_wiimote_close > > > >> case status of > >> True -> putStrLn "OK" > >> False -> putStrLn "FAIL" > > > > Matching Bool values use "case" is no good style: > > > > putStrLn (if status then "OK" else "FAIL") > > > > Christian > > That's clever but you'd have to *know* haskell to *know* you could do > that! Point-free (pointless!) is something I have yet to fully tackle, > it looks like a great thing. Function composition is something else for > my brain to remember exists in the language! > > IIUC: given a Ptr8 Word, call c_wiimote close then 'functor map' the > 'section' (== 0) over the single entry in the list... what list? I am > confused again because I cannot see a list, c_wiimote_close answers a > pointer. No list here, fmap 'lifts' a function to any Functor. Here the Functor is IO. Generally, for any Monad which is also an instance of Functor (any Monad should be), fmap function monadicThingy ought to be the same as do value <- monadicThingy return (function value) which is the sugared version of monadicThingy >>= return . function > > I understand (== 0) rather than (0 ==) though, that's something! Both should be the same function. > > Thanks for your time. > > :) ------------------------------ Message: 4 Date: Sat, 22 Jan 2011 00:03:07 -0600 From: aditya siram <aditya.si...@gmail.com> Subject: [Haskell-beginners] Question about List Type Constraint and Null To: beginners <beginners@haskell.org> Message-ID: <aanlktin+rp2jagfmid0mhmo6sk_9e2-wlhfx5xepg...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi all, The following function gives me an "Ambiguous type variable `a' in the constraint: `Read a' arising from a use of `res'" error: test :: Read a => String -> Maybe [(a,String)] test s = if null res then Nothing else Just $ fst $ head res where res = reads s The reason as 'jmcarthur' so patiently explained on IRC is that 'res' is used twice and the type constraint 'a' is different for each use, hence the ambiguity. I get that. But I have a further question why should 'null ...' care about the type of its list argument? Isn't it polymorphic? So it shouldn't make a difference that the 'a' inside res is ambiguous because we know for sure that it always returns a list of some kind. Thanks, -deech ------------------------------ Message: 5 Date: Sat, 22 Jan 2011 08:07:05 +0000 From: Magnus Therning <mag...@therning.org> Subject: Re: [Haskell-beginners] Question about List Type Constraint and Null To: beginners@haskell.org Message-ID: <4d3a9029.4080...@therning.org> Content-Type: text/plain; charset="utf-8" On 22/01/11 06:03, aditya siram wrote: > Hi all, > The following function gives me an "Ambiguous type variable `a' in the > constraint: `Read a' arising from a use of `res'" error: > test :: Read a => String -> Maybe [(a,String)] > test s = if null res then > Nothing > else > Just $ fst $ head res > where > res = reads s This code doesn't give me that error, in fact it gives me no error at all. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: mag...@therning.org jabber: mag...@therning.org twitter: magthe http://therning.org/magnus -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: <http://www.haskell.org/pipermail/beginners/attachments/20110122/c4b24d43/attachment-0001.pgp> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 31, Issue 21 *****************************************