Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Documentation
>>>
:set -XLambdaCase
>>>
:{
let memoFib = \fib -> \case 0 -> 0 1 -> 1 i -> fib (i - 1) + fib (i - 2) in memoFix 100 memoFib 50 :} 12586269025
memoFixMap :: Ord k => ((k -> State (Map k a) a) -> k -> State (Map k a) a) -> k -> a Source #
>>>
:set -XLambdaCase
>>>
:{
let memoFibM :: (Monad m) => (Int -> m Integer) -> Int -> m Integer memoFibM = \fib -> \case 0 -> pure 0 1 -> pure 1 i -> (+) <$> fib (i - 1) <*> fib (i - 2) in memoFixMap memoFibM 50 :} 12586269025
memoFixIntMap :: ((Int -> State (IntMap a) a) -> Int -> State (IntMap a) a) -> Int -> a Source #
>>>
:set -XLambdaCase
>>>
:{
let memoFibM :: (Monad m) => (Int -> m Integer) -> Int -> m Integer memoFibM = \fib -> \case 0 -> pure 0 1 -> pure 1 i -> (+) <$> fib (i - 1) <*> fib (i - 2) in memoFixIntMap memoFibM 50 :} 12586269025