>>> fromMaybe "" (Just "Hello, World!") "Hello, World!"
>>> fromMaybe "" Nothing ""Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:
>>> import Text.Read ( readMaybe ) >>> fromMaybe 0 (readMaybe "5") 5 >>> fromMaybe 0 (readMaybe "") 0
>>> fromMaybe "" (Just "Hello, World!") "Hello, World!"
>>> fromMaybe "" Nothing ""Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:
>>> import Text.Read ( readMaybe ) >>> fromMaybe 0 (readMaybe "5") 5 >>> fromMaybe 0 (readMaybe "") 0
>>> fromMaybe "" (Just "Hello, World!") "Hello, World!"
>>> fromMaybe "" Nothing ""Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:
>>> import Text.Read ( readMaybe ) >>> fromMaybe 0 (readMaybe "5") 5 >>> fromMaybe 0 (readMaybe "") 0
>>> fromMaybe "" (Just "Hello, World!") "Hello, World!"
>>> fromMaybe "" Nothing ""Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:
>>> import Text.Read ( readMaybe ) >>> fromMaybe 0 (readMaybe "5") 5 >>> fromMaybe 0 (readMaybe "") 0
>>> import Data.Word >>> :type asProxyTypeOf 123 (Proxy :: Proxy Word8) asProxyTypeOf 123 (Proxy :: Proxy Word8) :: Word8Note the lower-case proxy in the definition. This allows any type constructor with just one argument to be passed to the function, for example we could also write
>>> import Data.Word >>> :type asProxyTypeOf 123 (Just (undefined :: Word8)) asProxyTypeOf 123 (Just (undefined :: Word8)) :: Word8
evaluateOddPolynomial x [1,2,3] = 1 + 2*x + 3*x^2
evaluateOddPolynomial x [1,2,3] = 1 + 2*x^2 + 3*x^4
evaluateOddPolynomial x [1,2,3] = 1*x + 2*x^3 + 3*x^5
>>> readMaybe "True" ?: False True
>>> readMaybe "Tru" ?: False False