[Haskell-beginners] Improve my FFI code please...
Edward Z. Yang
ezyang at MIT.EDU
Fri Jan 21 10:36:30 CET 2011
Excerpts from sean's message of Fri Jan 21 04:09:23 -0500 2011:
> Daniel, you have confused me. In my RWH book there is a test from the
> PCRE example of nullPtr == x, so I just did my code using a case
> instead, I am sure it's correct!?!?!? If I run my program with the
> Wiimote off, it prints FAIL and if I press the red sync. button it
> then prints out OK and the memory address of the allocated structure
> so it surely must be workng as I expected?
A more direct answer is that you need to use a guard in this case:
case x of
x | x == nullPtr -> ...
Or maybe in this case, using a regular conditional would be better.
You can pattern match against constructors (things that are capitalized);
variable names (lower-cased) will just assign new variables.
Cheers,
Edward
More information about the Beginners
mailing list