Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
fib :: Integer -> Maybe Integer
|
||||
fib n
|
||||
| n < 0 = Nothing
|
||||
| otherwise = Just $ real n
|
||||
where real 0 = 1
|
||||
real 1 = 1
|
||||
real n = real (n-1) + real (n-2)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import Data.Function (fix)
|
||||
|
||||
fib :: Integer -> Maybe Integer
|
||||
fib n
|
||||
| n < 0 = Nothing
|
||||
| otherwise = Just $ fix (\f -> (\n -> if n > 1 then f (n-1) + f (n-2) else 1)) n
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
ghci> map fib [-4..10]
|
||||
[Nothing,Nothing,Nothing,Nothing,Just 1,Just 1,Just 2,Just 3,Just 5,Just 8,Just 13,Just 21,Just 34,Just 55,Just 89]
|
||||
23
Task/Anonymous-recursion/Haskell/anonymous-recursion-4.hs
Normal file
23
Task/Anonymous-recursion/Haskell/anonymous-recursion-4.hs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
fib :: Integer -> Maybe Integer
|
||||
fib n
|
||||
| n < 0 = Nothing
|
||||
| otherwise =
|
||||
Just $
|
||||
(\f ->
|
||||
let x = f x
|
||||
in x)
|
||||
(\f n ->
|
||||
if n > 1
|
||||
then f (n - 1) + f (n - 2)
|
||||
else 1)
|
||||
n
|
||||
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
print $
|
||||
fib <$> [-4 .. 10] >>=
|
||||
\m ->
|
||||
case m of
|
||||
Just x -> [x]
|
||||
_ -> []
|
||||
Loading…
Add table
Add a link
Reference in a new issue