[Haskell-beginners] Improve my FFI code please...
Edward Z. Yang
ezyang at MIT.EDU
Fri Jan 21 00:44:21 CET 2011
The code looks basically fine. Good job getting to this point.
* It is probably a good idea to give Ptr Word8 a newtype; something like
Wiimote, to semantically represent what it is.
* Everyone loves bracketing functions! Write the function
withWii :: String -> (Ptr Word8 -> IO ()) -> IO ()
Don't call the inner lambda if getting the Wiimote fails.
* You can probably simplify 'test' a little bit by using exceptions
and guards. For example, instead of 'case status' you can write
'when (not status) $ error "FAIL"'. But this is a matter of taste
and what you have isn't nested too deep.
Cheers,
Edward
More information about the Beginners
mailing list