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

/fpt/ - Functional Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 182
Thread images: 6

File: 1482831679047.jpg (106KB, 400x400px) Image search: [Google]
1482831679047.jpg
106KB, 400x400px
Next-level programming thread.
Let the New Year bring you pure and immutable joy and happiness! May anger, despair and sorrow never be evaluated!
Happy New 2017 year!
Last one: >>58174033

Resources:
>Erlang
http://learnyousomeerlang.com/content
>>Elixir
http://chimera.labs.oreilly.com/books/1234000001642/index.html
http://elixir-lang.org/learning.html
>F#
http://fsharp.org/learn
>Haskell
https://en.wikibooks.org/wiki/Haskell
https://0x0.st/pbp.pdf
>Lisps
>>Common Lisp
http://gigamonkeys.com/book
http://www.cs.cmu.edu/~dst/LispBook/book.pdf
Common Lisp Recipes
Land of Lisp
An Introduction to Functional Programming Through Lambda Calculus
>>Clojure
http://www.braveclojure.com/foreword/
The joy of Clojure
>>Scheme
SICP
Essentials of Programming Languages
How to Design Programs:
http://www.ccs.neu.edu/home/matthias/HtDP2e/
Art of the Propagator
Little Schemer
The Seasoned Schemer
The Scheme Programming Language by Kent Dybvig
Realm of Racket
Lisp in Small Pieces
>OCaml
https://realworldocaml.org/
http://ocaml.org/learn/tutorials/
>Scala
Functional Programming in Scala (Chiusano and Bjarnason)
Atomic Scala (Eckel and Marsh)
Programming Scala (Wampler and Payne)
Programming in Scala (Odersky, Spoon and Venners)
>Web languages
>>Elm
https://guide.elm-lang.org/
>>PureScript
http://www.purescript.org/learn/
>>
can you stop making this fuckign thread? theres already a retarded functional general thread with 60 posts
>>
>>58214762
I keep telling him to change stuff in the OP to see how many times he'll remake it.

Probably not any more after reading this.
>>
>>58214785
I said it is the last time, it will be the last time.

Also:
>The OP seems to imply that it's a good way to learn Scheme.
"Resources:" is written in the OP, not "Resouces to learn language X"
EoPL uses Scheme, so it will be Scheme resource.
I will thinkj about that by next bumplimit.
>>
>>58214672
>HaskLEL is useless and, pure functional and stateless languages are a meme
>Lisp is only used for third class text editors
>SICP is not a good book and this is why it's given away for free
>Anime is shit
>Maki a slut
>C++ is much better than C
>Java is the language of the future
>JS is a good choice for server side
>The best software engineers are indians
>>
I don't dislike this thread but thank you for using an anime image
>>
Talking again about logic programming.
Some anon around said that modern logic programmers use Haskell for logic programming.
Does it mean Haskell supports backtracking?
If so, how?
>>
>>58214846
>EoPL uses Scheme, so it will be Scheme resource.
EoPL uses Scheme incidentally, it doesn't teach it. See also: SICP.
>>
>>58215077
Please make a list what should be redone in OP.
>>
>>58215683
1. Delete OP.
2. Try again.
3. Goto 1.
>>
>>58215964
Your opinion is taken into consideration, thanks.
>>
>>58216003
You're welcome. Now please delete the thread and try again.
>>
>>58216032
Not possible.
>>
>>58216058
You have failed utterly, OP.
>>
I've forgotten to check this.
>>58205609
>You can add, "Slime - The Superior Lisp Interaction Mode for Emacs" it's epic.

>Also easymod "emacs.d" configs for webdev and bunch of the functional languages https://github.com/purcell/emacs.d.
>>
I don't get about point-free notation.
If I don't give arguments with function, does it mean I must specify a signature for the function?
>>
>>58217190
wat? no that doesn't change anything. If you needed a type annotation with point-free style you need it in a pointful style too. It's exploiting a beta-equivalence of terms. If it confuses you don't bother doing it, it's more a style thing anyway.
>>
s
>>
>>58218683
Are there some functions where you can't use point-free notation?
>>
>>58220497
man i'm not even sure I understand that question. here, this is what you gotta know if `f x ≡ g x` then `f ≡ g`, this is axiomatic.
>>
>>58220574
I just don't understand how functions are evaluated if point-free notation is used.
How would abs(x) function look in point-free notation?
>>
>>58220615
it's an equational thing, anon. here's a different example
map isDigit
\xs -> map (\x -> isDigit x) xs
In both cases we get a function which wants a list of Char's, and along the way we make use of another function that needs a single Char, but since, in both cases, the argument appears all the way on the right, we can drop the lambda completely.
>>
>>58220735
here's a thing that probably won't help you understand anything:
http://blunt.herokuapp.com/#input=%5Cxs%20-%3E%20map%20(%5Cx%20-%3E%20isDigit%20x)%20xs
>>
>>58220735
Well, example with map gives more clearance, but I'm not proficient Haskell, so I can't understand what -> mean.
Moreover, how guards are set if indentation is ommited?
>>
up
>>
Is little schemer good to read before HtDP? Will I just be wasting time learning shit I will learn anyways? My goal is to be able to at least fuck around and read real scheme programs pretty fast, so I stay interested, but go deeper in my learning with HtDP.
>>
>>58221212
HtDP uses Scheme as a language to show principles, but Little Schemer is more about Scheme itself, so, if you want to practice Scheme, Little Schemer is a good choice.
>>
Is it permissible to use LOOP in CLisp?
>>
I'm the organizer of a functional programming meetup in my city. What should I do with it?
>>
>>58222356
Bring beer
>>
What the fuck are you doing?
/fpt/ is in here
>>58212017
>>
>>58222896
/fpt/ is here
>>
Reminder that OP made this thread well into the real thread because he was mad that he didn't make it this time

>>58223301
>>
>>58223323
Reminder that thread is not real, because:
>no FP-related OP
>link to /dpt/ is given (no need since /dpt/ iterates faster)
>no Next-level programming thread
>no new resources added though there were marked ones
>Opinions listed in resources
>>
>>58223510
>linking /dpt/ (despite always linking /fpt/ in /dpt/) is not allowed
>i didn't get the lisp reference so it's not fp related, even if it is programming related
>it didn't copy my OP posts word for word so it's wrong
>it didn't add resources, OP made a mistake so lets ignore the entire thread rather than simply adding resources as a post
>"Scala is shit" is an opinion

Wow, suddenly it all makes sense why you ignored 80 fucking posts and 30 different posters and decided to thread split two hours after the thread was made.
It's totally not like you wanted to be OP or anything.
>>
>>58223543
>linking /dpt/ (despite always linking /fpt/ in /dpt/) is not allowed
/dpt/ OP doesn't link /fpt/
/fpt/ OP doesn't link /dpt/
New /dpt/ is created every 8-12 hours
New /fpt/ takes a half of week
How come you need to link /dpt/ since it's faster?
>i didn't get the lisp reference so it's not fp related, even if it is programming related
>himegoto
>lisp
Tell me more
>inb4 but muh brackets
>didn't copy my OP posts word for word so it's wrong
See above and below.
>it didn't add resources, OP made a mistake so lets ignore the entire thread rather than simply adding resources as a post
>given "Scala is shit"
If it were mistake, there would be no opinions
>"Scala is shit" is an opinion
>implying it's not
>you ignored 80 fucking posts
At the time it wasn't 80.
>It's totally not like you wanted to be OP or anything.
what
>>
>>58221566
please respond
>>
Anyone got any links to open source project so using functional languages?

I'm ok with using FP for small Project Euler type stuff but for real world usage I can't see how FP is Moreno intuitive to use than non-FP styles.
>>
>>58224545
How about xmonad?
>>
>>58214672
Is there hentai of her?
>>
Can we talk about functional programming language implementation?

How do you build a virtual machine for one? How do you optimize?
>>
File: SCR_1483016280.png (23KB, 377x345px) Image search: [Google]
SCR_1483016280.png
23KB, 377x345px
Haskell fags, this is actually retarded.
I know you have a raging hard-on for guards (and that's fine!), but that doesn't mean you have to write if statements like this.

Why can't picrelated just be like it is in all other sane languages:
pts :: Int -> Int
pts x =
if x == 1
then 10
else if x == 2
then 6
else if x == 3
then 4
else if x == 4
then 3
else if x == 5
then 2
else if x == 6
then 1
else 0

Or you can put "then N" on the same line as "else if". Anything but picrelated.
The Haskell wikibook is great and all, but this shit is ruining the whole experience.
>>
>>58225039
I have no idea why they decided to do this.
You could also use the MultiWayIf extension

if | x == 1 -> a
| x == 2 -> b
| x == 3 -> c
| otherwise -> d
>>
>>58225039
Tbh learning Haskell at the moment and think this is retarded as fuck. I like guards though
>>
>>58225039
>>58225189
>>58225218

That's a teaching example for if expressions, you derps. Barring just using a Map, this is how you'd actually do it:

pts 1 = 10
pts 2 = 6
pts 3 = 4
pts 4 = 3
pts 5 = 2
pts 6 = 1
pts _ = 0
>>
>>58225294
As I said, I don't care if you're supposed to use guards or pattern matching or whatever is best in that case. All I'm asking is why the fuck are ifs indented like that?
>>
>>58225318
I see you've added the phrase 'pattern matching' to your argument.

Try this:

test x =
if x == 10
then 12
else if x == 12
then 10
else if x == 13
then 13
else 0
>>
>>58225369
That's what he was arguing from the beginning
>>
>>58225369
anon, no.
Look at my original post. My code snippet works and looks like it's supposed to (with one level of indentation, not six). I'm wondering why does the code snippet from Haskell wikibook on that pic have six levels of indentation when only one is actually needed.
>>
>>58225414
Never mentioned pattern matching.

>>58225431
This is a non-discussion; it essentially runs like so:
"Hey guys, I know I'm not supposed to do this, but why is it so ugly?"
"It's so ugly because you're not supposed to do it."
>>
>>58225457
You've misunderstood him yet again

Yes, >>58225369 is ugly, but in the pic in >>58225039 it's a lot uglier, with insane indentation.
>>
>>58225473

All of the examples in these two posts (there are three if you count the image) are ugly because you're not supposed to do it this way:
>>58225039
>>58225369
>>
>>58225457
>>58225494
Just because it's not the best solution doesn't mean that we have to indent if statements in an absolutely insane way.
At least to me it seems insane. I'm very new to functional languages, so I was hoping somebody would explain that crazy indentation and maybe then it wouldn't look insane to me.

>"It's so ugly because you're not supposed to do it."
No, it's ugly because somebody indented it that way. Compiler accepts my version from the original post, yet the wikibook has insane indentation for some reason (which I'm trying to find out).
>>
>>58225494
You're still missing his point, which is why are they indenting the if's that way?

>ugly because you're not supposed to do it this way
You've got it the wrong way round.
You're not supposed to do it that way because it's ugly.
And even then, that's because someone saw that it was uglier than it needed to be and added it in.
>>
>>58223855
LOOP is a standard CL macro, therefore it should be implemented in CLisp.
http://clhs.lisp.se/Body/m_loop.htm#loop
>>
>>58225473
>with insane indentation.
Can't you just put it in braces?
>>
>>58225527
>>58225528
All of the syntax resulting from chaining a daft number of if expressions is ugly.

This is because you're not supposed to chain a daft number of if expressions.

You're supposed to go for cases, pattern matching, Map lookup, or similar: something that abstracts out the branching.
>>
>>58225563
Are you just ignoring the discussion at this point?
I assume you know what we're actually talking about.
>>
>>58225569
In functional languages there are opportunities to abstract out branching constructs like if expressions.

You should use them.
>>
>>58225563
It seems like you're trying to avoid my question.

>All of the syntax resulting from chaining a daft number of if expressions is ugly.
Sure, I can agree with that. So we have to write them in the most ugly way that doesn't make any sense and wouldn't work in languages where indentation matters?
>>
>>58225586
Ah, so that's a yes then.
>>
>>58225591
>>58225600
You don't have to write them at all. You could just:

ifThenElse True x _ = x
ifThenElse False _ y = y


This is lambda calculus, you chumps. There's no need to run straight for the syntax involved in an 8-way if expression chain.
>>
>>58225612
>Yes yes yes yes I am ABSOLUTELY avoiding the discussion!
so eager
>>
>>58225612
i just want to fucking know why i constantly see haskell code where people are pressing their tab button way more times than necessary

don't (you) me if you don't know the answer to this particular question
>>
>>58225647
You haven't posted anything relevant to the discussion in your last two posts.

>>58225650
Functional languages are a sequence of expressions, not statements. Graham discusses this difference in structure in 'On Lisp':
http://unintelligible.org/onlisp/onlisp.html

If you haven't noticed, there are no more '(You)'s, so I'm happy to oblige.
>>
>>58225684
>You haven't posted anything relevant to the discussion in your last two posts.
you haven't posted anything relevant to the discusison since it started
>>
File: 1479580200592.jpg (65KB, 680x680px) Image search: [Google]
1479580200592.jpg
65KB, 680x680px
>>58225586
I don't the question at all.
Is there the problem of having multilayered if-branches?
Should I use them?
Shouldn't I use them?
Can't I have multiple IFs not placed one in each other?
me confused
>>
>>58214672
Is lisp worth learning? What is good about it?

For reference I've only got any experience in python, c, and visual basic
>>
>>58225684
i'll go email a smart person. this fourchan thing isn't working out.

>>58225704
exactly.
>>
>memeprogramming has its own stable thread
>>
>>58225684
Here are your .d.o.t.s.
>>
>>58225732
It has two threads. This one split from >>58212017
>>
>>58225704
You're still not actually contributing anything here. Don't you have a point to make?

>>58225718
>I don't the question at all.
Clearly.

If if expression syntax is completely redundant: as demonstrated, you don't need it in a lazy lambda language: you get branching for free. The only reason the syntax exists is to stop newcomers going 'where are my branching constructs?'

You *shouldn't* use extensively chained if expressions because there are much more elegant (pretty and simple) abstractions of branching that are far better suited for the job. Like: case, pattern matching, lookup.
The reason that the if syntax is ugly is because it *shouldn't be used in excess*.

And if you must, use multi-way if. But you're probably better off just using C instead.

>>58225724
Have fun.
>>
>>58225764
>multi-way if
i.e. multiple IFs on one level?
>>
>>58225039
I think the answer after all this is "there is no real reason"

>>58225807
MultiWayIf is a language extension that lets you chain if-elses with case syntax

i.e.

if | cond1
| cond2
| cond3

aka

if cond1 then
else if cond2 then
else if cond3 then

becomes

case () of
() | cond1 ->
() | cond2 ->
() | cond3 ->
>>
>>58225807
See >>58225189

It's ugly as fuck.
>>
>>58225818
>I think the answer after all this is "there is no real reason"
Because if that's the case, I'm going to go on a wiki edit spree and change every single one of those ugly ass snippets into something that makes sense.
>>
>>58214862
>sarcasm
>>
>>58225837
I wouldn't, it's entirely possible there's some archaic reason like "back in Haskell '98 this was necessary"
>>
>>58225850
And I'm pretty sure that's a part of the reason (some minor googling led me to that conclusion). I just wanted to know why it was necessary back then.
>>
>>58225189
How does it differ from guards then?
>>
>>58225837
If you do that just make sure you get rid of all the redundant 'if' bollocks. It teaches newbies bad habits.

And makes them very confused, as we've discovered.

>>58225886
Very little. That's one of the reasons it's so ugly: it's very much non-orthogonal.
>>
>>58224896
>How do you build a virtual machine for one
There was a talk given by Xavier Leroy (OCaml dad) about the implementation of functional languages, you could start with this.
>>
>>58225886
it doesn't
>>
>>58225897
>And makes them very confused, as we've discovered.
THE ONLY ONE CONFUSED IN THIS ENTIRE THREAD WAS YOU.
You still are, after all this. It's quite baffling. At this point I have nothing else left but to assume malice.
>>
>>58220962
help
Moreover, are there any situations where you can't use point-free notation?
>>
>>58220962
\x -> e
is a lambda
x is the parameter, e is the result

>>58225967
there are many cases where pointfree is inconvenient
>>
>>58225979
>there are many cases where pointfree is inconvenient
Such as?
>>
>>58225955
You seem to have decided to repeat "you're not engaging in the discussion" so much that you've been too confused to actually engage in the discussion, which I think is hilariously ironic.
>>
File: pointless.png (4KB, 795x54px) Image search: [Google]
pointless.png
4KB, 795x54px
>>58226024
>>
>>58226116
Can you explain to me why the person that was writing code in that pic pressed tab six times instead of one?
>>
Which one of them is the most suited for AI?
>>
>>58226172
I've heard Lisp is pretty good for that (something about it being simple to write programs that write themselves in Lisp). But that was decades ago, I'm not sure it's still used in the industry to this day.
>>
>>58226163
That's good indentation style for if-expressions.

It looks daft for six 'if's in a row because six 'if's in a row is a daft thing to do.

Haskell is a functional language. Functional languages are built from expressions, whose arguments determine indentation level. The 'if' syntax in Haskell is just syntactic sugar for a function of three arguments.
This is in contrast to imperative languages, whose block-like structure is reflective of their construction from series of statements.
Once again, Graham discusses this in On Lisp: I've posted a link above.

It's really not that confusing:
functional languages =
look like $ this $
for example

they are structured =
from functions $
whose arguments
determine indentation level


imperative languages;
are a series;
of statements;
broken (into) {
blocks like this;
which reflects;
their construction;
}
>>
File: 1410268942410.png (639KB, 1472x1022px) Image search: [Google]
1410268942410.png
639KB, 1472x1022px
>>58226249
>The 'if' syntax in Haskell is just syntactic sugar for a function of three arguments.
At this point I don't even care if this isn't true (I couldn't get a concrete answer from REPL with
:info if
, so I'll just trust you). This explanation makes vague sense to me as a beginner, so I'll accept it as truth.
Thanks.
>>
>>58226327
:info
only works on in-scope variables, not keywords
there's a request on GHC's trac to add a :binfo (:beginnerinfo)
>>
>>58226196
It is.
It's also used a lot for computational linguistics (along with prolog), and a lot of that is how easy it is to make grammatical tree structures for evaluation.

I remember a woman making a massive neural net for translating proverbs. It was pretty cool, and it was made in Common Lisp.
>>
>>58226249
Well, if in Haskell can be a function because of lazy evaluation.
You could have a weird as fuck imperative language doing that too. It would not be a good language, but it would be possible.
>>
>>58226327
That's because 'if' is *syntax*, not a function per se. Try playing around with this:

myIf True y _ = y
myIf False _ z = z


It's a branching construct (like if-then-else), but defined as an actual function (rather than just syntax). It will work exactly like if-then-else syntax, bar the fact that you need to parenthesize the arguments (since with the syntactic version, the keywords separate out the arguments).

myIf (0 == 1) "TRUE!" "FALSE!"
if 0 == 1 then "TRUE!" "FALSE!"


This demonstrates the redundancy of the keyword version. As I said earlier, I'm pretty sure it was just put in in order to stop newbies asking "where's 'if'?".

Furthermore, now that you see it's basically just an ugly function, you understand why it's good style to indent the arguments: because that's what you do to functions.

>>58226419
See >>58225764
>you don't need it in a lazy lambda language: you get branching for free
I think we're making the same point here.
>>
>>58226471
My bad, should read:
if 0 == 1 then "TRUE!" else "FALSE!"


You can probably tell I don't like this syntax.
>>
>>58226249
Does it mean that FP programs are constructed from little functions, which evaluate more little functions and ad infinitum?
>>
>>58226471
with the RebindableSyntax extension you can rebind if, which is convenient if writing a DSL with branching
>>
>>58226489
Yeeessssssss, they are. It's functions all the way down (at least with the 'real' languages).

Now I feel like this has all been worth it.

>>58226490
I fucking hate 'if'.
>>
>>58226489
in practice they normally have primitives for performance, but the lambda calculus is turing complete:

e : \x.e
e e
x


you can encode bools really easily

type Bool = forall a. a -> a -> a
true, false :: Bool
true a _ = a
false _ b = b


true and false are just functions that choose between two options, in fact in this encoding,

if x then t else f
is just
x t f
>>
>>58226508
>It's functions all the way down (at least with the 'real' languages).
What are 'unreal' languages?
>>
>>58226583
C++, that's what Unreal Engine is written in.
>>
>>58226583
Languages that are the square root of a negative number
>>
>>58226600
this doesn't deserve triple dubs
>>
>>58226583
Lisps
>>
>>58226583
The ones that aren't manly functional languages, of course.
>>
>>58226489
FP programs come in two flavors.

Typeless functional languages (e.g. lambda calculus), which are constructed from only two basic primitives:

1. function abstraction (lambda functions) e.g. \x -> Y
2. function application e.g. f x

Well-typed functional languages build on top of this with two more primitive types

3. constructor application (building data) e.g. Just x
4. pattern matching (taking apart data) e.g. case x of Just y -> Z; Nothing -> W

1 is the inverse of 2, and 3 is the inverse of 4. Together, these two (mostly orthogonal) concepts form the core of languages such as Haskell.

The rest of the expression syntax is syntactic sugar on top of these four basic primitives. That said, the majority of Haskell goes on in the type system, not the actual programs, so just understanding these concepts isn't enough to fully understand Haskell, although it is enough to fully understand the operational semantics of Haskell
>>
>>58226249
I think it would be more accurate to say that indentation in Haskell conveys blocks, at least syntactically

For example, you can do this in Haskell

f = do { x; y; z; }

or you could write the same as this
f = do
x
y
z


Basically, as far as blocks (not expressions) are concerned, every time you increase the indentation level, it's equivalent to writing a {. Every time you decrease it, it's equivalent to writing a }. And every newline at the same indendation level is equivalent to writing a ;

So you can either write this
case x of { A -> a; B -> b; C -> c }

or this
case x of
A -> a
B -> b
C -> c
>>
>>58226629
But Lisps evaluate functions in functions too, aren't they?
>>
>>58226720
Indentation is actually transformed into "virtual" {s ;s and and }s
Anon was completely wrong in pretty much everything he said.


>>58226730
Lisps have all this list and tree nonsense going on.
It's pretty trashy and unclean desu.
>>
>>58226739
>a language designed for list processing has lists built in to the language
criminal
>>
>>58226763
>an (allegedly functional) programming language has lists that are as primitive as application or function abstraction
extremely criminal
>>
>>58226720
Example

main = do
putStrLn "What's your name?"
name <- readLine
when (name == "anon") $ do
putStrLn "Wow, what a faggot you are"
putStrLn "Commencing jihad"
unsafeLaunchMissiles
putStrLn ("Goodbye, " ++ name)


this is equivalent to

main = do {
putStrLn "What's your name?";
name <- readLine;
when (name == "anon") $ do {
putStrLn "Wow, what a faggot you are";
putStrLn "Commencing jihad";
unsafeLaunchMissiles;
};
putStrLn ("Goodbye, " ++ name);
}
>>
>>58226791
>putStrLn ("Goodbye, " ++ name)
use Text.Printf.printf

printf "Goodbye, %s" name


bonus: it doubles as both IO () AND String


Also, it's sad we haven't got ArgumentDo, which would let you avoid that $
>>
>>58226811
>it doubles as both IO () AND String
What is this magic
>>
>>58226822
it's variadic too
>>
File: printf.png (8KB, 435x238px) Image search: [Google]
printf.png
8KB, 435x238px
>>58226822
>>58226831
>>
>>58226831
The more Haskell I learn, the less I feel I know
>>
>>58226720
>>58226791
Using do-notation as an example of Haskell not following the normal style of functional indentation is a bit silly, since do-notation is just a syntactic construct that was literally designed to allow you to structure your monadic code in a similar style to imperative languages.

The whole point of do-notation is to make Haskell look like imperative languages, rather than its natural shape.
>>
>>58226862
:^)

it's polymorphic in its return type, so you can choose what it returns (within a certain set of limits)
it's allowed to return a string, but it's also allowed to return an IO (), and it's also allowed to return an (thingItCanPrint -> thingItsAllowedToReturn)

when you use it in an IO do block, it knows the type must be IO ()
when you call it again, it knows the type must be something -> something
when you use it as a string, it knows it has to be a string

otherwise it's an error
>>
>>58226811
>Also, it's sad we haven't got ArgumentDo, which would let you avoid that $
I don't think it's that bad; makes it pretty clear what you're applying to what
>>
>>58226892
Do-notation is a perfectly reasonable style for representing continuation passing.
It may be intended to look imperative, but it's as functional as you can get.
>>
>>58226822
>>58226831
Pretty simple type class stuff

For example, here's how you could write a variadic ‘sum’ function to sum up any number of doubles
class SumType r where
mysum :: Double -> r

instance SumType Double where
mysum d = d

instance (a ~ Double, SumType b) => SumType (a -> b) where
mysum d c = mysum (d+c)


(I'm sure with some extra magic you could make it work for 0 arguments as well, but this is probably the simplest presentation to understand)
>>
>>58226909
>It may be intended to look imperative, but it's as functional as you can get.
That's almost literally what I just said.

Here's what has happened so far:

>me: functional languages are naturally quite indented whereas imperatives tend to look blocky
>you: but Haskell has do-notation!
>me: that's right, they added it to allow pure (and naturally indented-looking) code to have a blocky look if desired
>you: but do-notation is for pure functions!
>me: [this post]
>>
>>58226892
Haskell uses blocks for more than just ‘do’ notation, though. It also uses them for ‘case .. of’, ‘let .. in’, ‘where’, ‘if’, ‘class’ and probably more I'm forgetting
>>
>>58226973
I think you're confusing me for someone else.
>>
>>58226981
Those are all syntax...

Plus this whole thing started with some guy saying 'why do we indent if-expressions?'

>>58226986
Well, that's the line of discussion, regardless of where you came in.
>>
>>58227010
>Those are all syntax...
Case and class would not work without blocks.
>>
>>58227010
>Those are all syntax...
Teh point is that blocks are a fundamental part of haskell syntax and that indentation in Haskell is meaningful in the sense that it opens and closes these blocks.

Any other form of indentation is a completely arbitrary stylistic choice by the author, such as the if/then/else example, but it has no impact whatsoever on what it means to the compiler - unlike most forms of indentation.

The reason I'm being pedantic is because unlike languages like C, indentation *does* matter to Haskell, so it's important distinguish between meaningful indentation and meaningless indentation in that sense. And the only forms of meaningful indentation are when they replace block syntax ({;}), which crops up often in Haskell
>>
>>58227075
Wait a second.

What you're saying is...

Those things aren't functions use blocks?

And so...

Given that functional languages only have an indented look given that arguments to functions provide this appearance...

If you write things that *aren't functions*...

You don't get this appearance?

This appearance of functions?

So what you're saying is... things that aren't functions... don't look like functions?

Jesus Christ, you're right! Functional languages only look like functional languages when you use functions! Genius!
>>
>>58227114
That kind of sarcasm doesn't work when everyone fucking disagrees with you, you retard.
>>
>>58227087
I agree with all this, but it's not relevant to the point I'm making.

Any syntactic construct can have arbitrary indentation rules (fair enough).

I'm only arguing that functional languages tend to have a certain appearance because of their unit of construction (the function). Of course any deviation from this (like syntax) will result in a deviation from the normal appearance. Look at import statements, for example.
>>
>>58227145
It's not sarcasm, you derp: every statement in that post is true.
Perhaps you meant flippancy or irreverence or something.

I would say that this guy is on the right lines: >>58227087
>>
>>58227167
To imply that a functional language can't deviate from the untyped language calculus is nonsense.
>>
>>58227167
>>58227178
Like Lisps. Lisps are functional, but their structure is VERY different from the untyped lambda calculus, and fundamentally so (it's not "there's a not-very-functional toplevel", it's "every expression is extremely different to the lambda calculus")
>>
>>58227178
I did no such thing.

To infer that a functional language can't deviate from the untyped language calculus is nonsense.
>>
>>58227198
You said blocks weren't functional.
That's wrong, and you know it.
Declarations are functional, in fact declarations are DECLARATIVE.

Just like how >>58226249 is completely wrong.
>>
>>58226249
looks like Python desu.
Is Python functional?
>>
>>58227221
I never said blocks weren't functional. I said they were syntax, not functions.

They can be syntax for functional concepts, like if-then-else.

If you use actual functions, good style is to indent with respect to arguments. That's why that damn wikibook decided to indent its if-expressions: to reflect the fact that they are just sugar for a functions.
BUT if you use novel syntax, there are no rules. You can do as above, or you can indent block-style, like 'do'.


tl;dr
Functions generally look indented.
Keyword syntax can be whatever the fuck you like: indented, block, whatever.

I don't understand why this is so hard to grasp.
>>
>>58227274
You could probably write purely functional programs in Python, but it's not designed for that so the code would end up being awkward and inefficient.
>>
>>58227274
The second part of the code looks a bit like Python, because it's a series of statements (which is what Python usually comprises of).

You can do functional in Python, but it's generally discouraged as not Pythonic.
it_also(ends_up(looking_like(this)))
.
Weird line break rules in Python.
>>
>>58227297
I should clarify that
>syntax can be whatever the fuck you like: indented, block, whatever.
Was with respect to language designer, not programmer.
>>
>>58227087
How do you implement guards without indentation?
>>
>>58228217
you know you can do guards on the same line, right?

f x | x == 2 =
>>
>>58228217
f x | even x = "foo" | odd x = "bar"
>>
>>58228217
You can implement them however you like, but I suspect you mean "how do you USE guards with indentation", to which >>58228273
>>58228296
are solid answers.

You could even IMPLEMENT them so that
f x =
| even x = "foo"
| odd x = "bar"

is valid code, but I'd say that that's pretty ugly.
>>
>>58215077
to be fair, that book is how I learned Scheme
>>
>>58228332
>You could even IMPLEMENT them so that
Wait
I thought that's the only valid code
>>
>>58228589
It probably is, I just never write them like that.
>>
>>58228589
>I thought that's the only valid code
Unless I'm misinterpreting you, it's invalid because you can't have the equals after f x when using guards
>>
>>58228652
Oh yeah, my bad. Then again, you could always implement them so that it was accepted, so in a way it emphasizes the point.

If you haven't guessed, I never use guards.
>>
>>58214672
You forgot Kotlin, bro
>>
>>58228712
Please, what is good resource to learn Kotlin?
>>
>>58228712
Kotlin isn't fp. It's just less retarded OOP.
>>
>>58229294
So still retarded then?
>>
>>58229301
yeah. it's basically on par with C#/Scala Lite
>>
>>58229317
What's so bad with Scala/Kotlin?
>>
>>58229526
Java
>>
>>58228712
>>58228986
>>58229294
>>58229301
>>58229317
>>58229526
>>58229544
>Kotlin
>/fpt/
Get it together, guys.
>>
?>>58229544
>>
>>58230283
We can always go back to >>58212017 if this thread keeps up
>>
>>58230459
I think we should just delete this one. OP decided to make it when the other was just 50 posts in, and /fpt/s take days to die.
>>
>>58230576
OP had some pretty autistic reasons.
Keep both threads bumped
>>
>>58214934
anyone?
>>
>>58230594
What were his autistic reasons?

Other than his being autistic, of course.
>>
>>58230892

see >>58223301
keep in mind this guy is allegedly the guy that makes ALL /fpt/s, so that's probably the real reason
>>
>>58230936
Jesus, I'd forgotten about that post. That is pretty autistic.
>>
>>58230860
please notice me
>>
>>58231768
I decided to learn about logic programming the other day, so I chose Curry (which is Haskell with logic programming 'bolted on' relatively neatly). De facto implementation is called PAKCS.

http://www-ps.informatik.uni-kiel.de/currywiki/_media/documentation/tutorial.pdf

I don't know how you'd go about implementing logic programming in Haskell, though I'm sure it's possible.
>>
Common Lisp is not functional you kikey nigger gook.
>>
>>58231889
type inference probably
>>
>>58231889
>I don't know how you'd go about implementing logic programming in Haskell
>Curry (which is Haskell with logic programming 'bolted on' relatively neatly)
Isn't that the answer?

What did you make to choose Curry over other LP languages?
>>
>>58231889
>I don't know how you'd go about implementing logic programming in Haskell, though I'm sure it's possible.
http://hackage.haskell.org/package/logict-0.6.0.2/docs/Control-Monad-Logic.html
>>
>>58232437
Isn't LogicT basically just a list monad transformer?
>>
>>58232437
I think a more appropriate link would have been:
http://hackage.haskell.org/package/logict-0.6.0.2/docs/src/Control-Monad-Logic.html

>>58232462
Lists or sets, you'd need some kind of multiple-value container.
>>
>>58232437
>>58231889
Better link

http://hackage.haskell.org/package/logict-0.6.0.2/docs/Control-Monad-Logic-Class.html

>>58232462
Lists give you backtracking, but not stuff like fair distribution, or efficient continuation composition
>>
>>58231889
>so I chose Curry (which is Haskell with logic programming 'bolted on' relatively neatly)
How is this different from something like Mercury (which is a haskell/prolog hybrid)
>>
>>58232631
Mercury was second choice.
What sealed it was the fact that there's a 'for idiots' explanation here:
http://www-ps.informatik.uni-kiel.de/currywiki/_media/documentation/tutorial.pdf
Thread posts: 182
Thread images: 6


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.