parsonsmatt / parsonsmatt.github.io

My Github pages website
Other
77 stars 25 forks source link

Don't expose the record selector #39

Closed josephcsible closed 4 years ago

josephcsible commented 4 years ago

If you expose the record selector, then this program crashes at runtime with a divide by zero error:

import NonZero
safeDivide i (NonZero j) = i `div` j
main = case nonZero 1 of
    Nothing -> putStrLn "One is zero?"
    Just one -> do
        let zero = one{ unNonZero = 0 }
        print $ safeDivide 1 zero
parsonsmatt commented 4 years ago

Great point, thank you! :smile: