[Haskell-beginners] Improve my FFI code please...

Christian Maeder Christian.Maeder at dfki.de
Fri Jan 21 13:46:36 CET 2011


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




More information about the Beginners mailing list