[Haskell-beginners] Improve my FFI code please...
sean at objitsu.com
sean at objitsu.com
Fri Jan 21 16:43:10 CET 2011
Quoting Christian Maeder <Christian.Maeder at 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.
:)
More information about the Beginners
mailing list