[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
functional programming
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 25
Thread images: 1
File: haskell logo.png (49 KB, 1000x716) Image search: [Google]
haskell logo.png
49 KB, 1000x716
haskell general
itt: post anything related to haskell
everyone from all levels welcome

ill start
why do people say haskell lazzyness is a failure
whats does ocammel do different than haskell
>>
if your language can't do linear fib in one line, then its probably garbage
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
>>
>why do people say haskell lazzyness is a failure

It's a bad default. Hard to think about performance, prone to space leaks.
>>
>>53681212
>zipWith
with a library function? of course
int f = fibonacci(n);
>>
>>53681212
int fibonacci(int n) { return n > 1 ? fibonacci(n-2) + fibonacci(n-2) : 1; }
>>
>>53681158
OCaml is more focused on hitting as many broad features as possible than being 100% functional, so it has OOP and imperative programming features but lacks controlled side effects. Where it really shines is in the module system, which makes it comfier than Haskell for big projects to me at least.
>>
>>53681212
fibs = let f a b = a : f b (a+b) in f 1 1
>>
>>53683834
fibonacci(n-2) + fibonacci(n-2)


thats not how it works
>>
>>53684062
just a typo. still a one line program.
>check mate functional programming
>>
>>53681212
: fib 0 1 2swap do over + swap loop nip ;
>>
>>53683988
does ocaml do oop right? i've only use it as a functional programming language
>>
>>53684091
I know. Still it's performance would be terrible
>>
>>53684091
>"linear fib in one line"
>"linear fib"
>int fibonacci(int n) { return n > 1 ? fibonacci(n-2) + fibonacci(n-1) : 1; }
Ain't linear, bud.
>>
>>53682240
Do you realize that laziness is forced by the type system? (namely, let polymorphism)
>>
>>53684293
int fib(int n){ int c=1,f=1,s=1,t; for (; c<n; c++,(t=f)&&(f=s)&&(s=s+t)); return s; }

a little garbage maybe, but still possible
>>
>>53683834
This will cause a stack overflow with large enough n.

C doesn't have tail call elimination, so any deep recursion is problematic.
>>
>JavaScript
function fib (n, f) { for (let [a,b] = [0,1]; n--; [a,b] = [b, a + b]) f(b); }
fib(6, (x) => console.log(x));
>>
>>53684376
It's still deep recursion, regardless of what happens to tails.

What nobody has addressed is how Haskell can actually evaluate non-tail recursion more efficiently that other languages, because of lazy evaluation!
>>
>>53684120
does OOP better than Java. not many people use the OOP, though
>>
>>53684635
>people don't use OOP
>even when it's done well
When will OOP finally die?
Data oriented programming is superior for low level needs, and functional programming is superior for high level needs. OOP is worthless, makes programming into a stupid game of "how can I over complicate my system?"
>>
>>53684635
better than scala too?
>>
>>53684580
If it is something where tail call elimination works, it gets translated by the compiler into a loop, so it doesn't consume unnecesary stack space.

The Haskell ones ITT aren't tail calls. When you make them tail recursive, they're more verbose than just using a loop.
>>
>>53684683
maybe, havent used Scala for more than a few minutes. it's probably completely different
>>
>>53684729
The Haskell one isn't tail recursive, but it is linear because of lazy evaluation and memoization
>>
>>53684751
scala oop is basically the modern oop.
it use a tree to represent the class hierarchy and have traits to simulate multiple inheritance without the diamond problem.

how it works in ocaml?
Thread replies: 25
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.