looks like Haskell
looks like Haskell
Posted Apr 18, 2013 2:46 UTC (Thu) by rsidd (subscriber, #2582)In reply to: looks like Haskell by droundy
Parent article: A taste of Rust
Posted Apr 19, 2013 9:24 UTC (Fri)
by peter-b (subscriber, #66996)
[Link] (4 responses)
Posted Apr 19, 2013 9:39 UTC (Fri)
by rsidd (subscriber, #2582)
[Link] (3 responses)
fib 0 = 0
is not just non-tail-recursive but incredibly inefficient. And every "functional" efficient version that I've seen is just too hard to understand (for me) by reading the code. And that's for a trivial beginner-level example.
Posted Apr 19, 2013 9:54 UTC (Fri)
by neilbrown (subscriber, #359)
[Link] (2 responses)
fib 0 = (1,1)
That's reasonably efficient - not sure how easy it is to make it tail recursive.
Posted Apr 19, 2013 10:19 UTC (Fri)
by rsidd (subscriber, #2582)
[Link]
Posted Apr 21, 2013 15:12 UTC (Sun)
by ballombe (subscriber, #9523)
[Link]
fib n = fibr n 1 1 where
(thought there are much faster algorithms to compute this)
Posted Apr 19, 2013 17:38 UTC (Fri)
by b7j0c (guest, #27559)
[Link]
looks like Haskell
looks like Haskell
fib 1 = 0
fib n = fib (n-1) + fib (n-2)
looks like Haskell
fib n = (a+b, a) where (a,b) = fib (n-1)
looks like Haskell
looks like Haskell
fibr 0 a b = (a,b)
fibr n a b = fibr (n-1) (a+b) a
looks like Haskell