[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
how do I into efficiency with haskell? e.g, what's head
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: 34
Thread images: 4
File: 1448554319630.png (49 KB, 1000x716) Image search: [Google]
1448554319630.png
49 KB, 1000x716
how do I into efficiency with haskell?

e.g, what's head normal form, weak head normal form, normal form
how do Into seq too, and also, general tips for more efficient acode with Haskell
>>
>how do I into efficiency with haskell?

You don't. The compiler decides whatever the fuck it wants to do with your code; all you can do is give vague hints and awkward voodoo incantations based on forum advice in the hope you can nudge the giant shitpile of obscure optimation hacks and lazy evaulation in the right direction. It's like writing SQL queries.

Alternately you can go full sperg mode and take a page from the Debian shootout benchmarks and start using unsafe pointers or writing raw intermediate GHCi Core but most people go back to using a productive language before they cross that frontier.
>>
Why do all Haskell introductory articles, tutorial and books use '++' for concating two lists? It sure looks readable but even with laziness it can bite.

Most of times I tried to implement algorithms efficiently it actually looked less readable than if I did it in imperative style (e.g. in C or Java). I'm less than newbie though.

What's the secret sauce? How does one translate algorithms written in imperative style (99%) into efficient and readable Haskell code?

I'm not OP.
>>
>>54365654
>how do I into efficiency with haskell?

You switch to Scheme.
>>
>>54365654
I think with a functional language like haskell you need to focus on making sure your algorithms arent trash. Thats what I've dont with F# and I've been able to write some reasonably well performing code, although nothing amazing.
As for language specific tips with haskell I'd recommend not using haskell
>>
>>54365716
>What's the secret sauce?

Real Haskell code uses one of the language's nine different flavors of arrays, which vary according to mutability, state, the Monad they operate in, and whether they contain primitive or boxed values.

It's a mess.
>>
>>54365784
>tfw i need to write an analytic essay on haskell by the end of the month
>tfw i haven't reached the part about monads yet
>tfw I'm gonna die

i thought it was gonna be easy /g/

what happened
>>
>>54365716
Use tail recursion and monadic features like map, reduce, etc
>>
>>54365778
so, is fsharp a less autistic lang?
>>
>>54365716
>Why do all Haskell introductory articles, tutorial and books use '++' for concating two lists?
Are you retarded? How else are you going to concatenate two lists faggot?
>>
>>54365708
name some productive languages
>>
>>54365716
is there any other way to concatenate two lists?
>>
>>54368527
Rust all the way, mang.
>>
>>54369844
tell me about it
is it used in the industry a lot
what are its niches, what it does best, worst, etc...
>>
>>54370041
> is it used in the industry a lot
Nope.
> niches, best, and worst
Can you imagine C with a seatbelt and manual transmission gears? Something like that.
>>
>>54370069
so, it's fast if it's like C, I also imagine it has C syntax and concepts like pointers
what is the seatbelt and manual transmission an analogy to
>>
>>54370111
Sorry, dude. Just took a lunch.
Ownership.
https://doc.rust-lang.org/book/ownership.html
>>
>>54367724
>>54368554
By making the algorithms that don't concatenate two lists.
>>
>>54371208
oh, you mean like copying the first and second list into another list?
>>
>>54370680
I'll give rust a go, I just hope I can learn it even though I've never learned C fully.
>>
switch to F#
>>
>>54371384
This, it's based
Microsoft are investing in it now and xamarin is coming along with F# support, it's statically typed goodness be it application development or web services
>>
>>54371384
what does fsharp offer?
>>
>>54371421
It actually has job listings
>>
File: reasons_to_use_haskell.png (154 KB, 401x305) Image search: [Google]
reasons_to_use_haskell.png
154 KB, 401x305
>>
>>54365654
>how do I into efficiency with haskell?
https://github.com/bitemyapp/learnhaskell

>head normal form
When something is in the form
Constructor ... ... ...
where ... are unevaluated thunks

>weak head normal form
this is basically HNF, the only difference is a slight semantic one due to the behavior of lambda expressions. (Evaluating a function to WHNF is a no-op)

>Normal form
When something is completely evaluated, e.g.
Constructor Val1 (CTor2 Val2 Val3) Val4


>how do I into seq
evaluating
x `seq` y
forces x “before” y. (Quotes because the actual order of evaluation is undefined, to explain it properly I would need to introduce the concept of _|_ first)
>>
>>54365716
>What's the secret sauce? How does one translate algorithms written in imperative style (99%) into efficient and readable Haskell code?
The secret is to realize that all of the algorithms you are familiar with are optimized and developed for imperative machines.

In a functional language, don't use imperative data structures and algorithms.

Use pure functional data structures and algorithms instead.
>>
>>54371384
>>54371418
F# is basically a worse Haskell that only gets used because it can interop with C#.
>>
>>54368527
C++
>>
Use prolog aka. the only good declarative programming language instead.
>>
>>54374153
eager > lazy
haskell is not for performance applications
>>
>>54374239
>adding a ! is too hard
You are essentially sperging out over syntactical differences
>>
File: 1459352572189.png (248 KB, 600x800) Image search: [Google]
1459352572189.png
248 KB, 600x800
>>
>>54374132
Algorithms are optimized for doing things by hand which has nothing to do with machines at all.

Humans just find it easier to move things around than create new things out of thin air.
Thread replies: 34
Thread images: 4

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.