>>> let fac n = if n <= 1 then 1 else n * fac (n-1) in fac 5 120This uses the fact that Haskell’s let introduces recursive bindings. We can rewrite this definition using fix,
>>> fix (\rec n -> if n <= 1 then 1 else n * rec (n-1)) 5 120Instead of making a recursive call, we introduce a dummy parameter rec; when used within fix, this parameter then refers to fix’s argument, hence the recursion is reintroduced.
>>> isInfixOf "Haskell" "I really like Haskell." True >>> isInfixOf "Ial" "I really like Haskell." FalseFor the result to be True, the first list must be finite; for the result to be False, the second list must be finite:
>>> [20..50] `isInfixOf` [0..] True >>> [0..] `isInfixOf` [20..50] False >>> [0..] `isInfixOf` [0..] * Hangs forever *
>>> "Hello" `isPrefixOf` "Hello World!" True >>> "Hello" `isPrefixOf` "Wello Horld!" FalseFor the result to be True, the first list must be finite; False, however, results from any mismatch:
>>> [0..] `isPrefixOf` [1..] False >>> [0..] `isPrefixOf` [0..99] False >>> [0..99] `isPrefixOf` [0..] True >>> [0..] `isPrefixOf` [0..] * Hangs forever *
>>> "ld!" `isSuffixOf` "Hello World!" True >>> "World" `isSuffixOf` "Hello World!" FalseThe second list must be finite; however the first list may be infinite:
>>> [0..] `isSuffixOf` [0..99] False >>> [0..99] `isSuffixOf` [0..] * Hangs forever *
>>> stripPrefix "foo" "foobar" Just "bar"
>>> stripPrefix "foo" "foo" Just ""
>>> stripPrefix "foo" "barfoo" Nothing
>>> stripPrefix "foo" "barfoobaz" Nothing
unsafeFixIO $ \r -> do forkIO (print r) return (...)In this case, the child thread will receive a NonTermination exception instead of waiting for the value of r to be computed.