3 ms·
With regards to generating random numbers, the Foreign Function Interface is also really useful. Here's a one-line wrapper around random(3). foreign import c
by abi 15y ago
With regards to generating random numbers, the Foreign Function Interface is also really useful. Here's a one-line wrapper around random(3).
foreign import ccall "stdlib.h random" c_rand :: CDouble -> CLong
- monopede 15y agoThat will most likely bite you since you're giving a pure type to a non-referentially transparent function. There is a reason why random functions are in a state monad or IO.
- JoshTriplett 15y agoIn particular, while you don't really care what order the compiler makes the underlying calls to the C function, you do care that it actually makes all the calls rather than CSEing them away. As a pure function, the compiler has every right to optimize away multiple calls to your FFI-bound random function, in favor of a single call and multiple references to the value.