[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: 281
Thread images: 23

File: 1482341093805.png (818KB, 1280x719px) Image search: [Google]
1482341093805.png
818KB, 1280x719px
Next-level programming thread.
The purest code is never written.

Last one: >>58105321

Resources:
>Elixir
http://chimera.labs.oreilly.com/books/1234000001642/index.html
>Elm
https://guide.elm-lang.org/
>Erlang
http://learnyousomeerlang.com/content
>F#
http://fsharp.org/learn
>Haskell
https://en.wikibooks.org/wiki/Haskell
>Lisps
>>Common Lisp
http://gigamonkeys.com/book
Common Lisp Recipes
Land of Lisp
>>Clojure
http://www.braveclojure.com/foreword/
>>Scheme
SICP
Little Schemer

Feel free to add more.
>>
>>58140581
I dunno why, but it pretty much reminds Prolog code:

fizzbuzz(fizzbuzz, X) :- 0 is mod(X, 15), !.
fizzbuzz(fizz, X) :- 0 is mod(X, 3), !.
fizzbuzz(buzz, X) :- 0 is mod(X, 5), !.
fizzbuzz(X, X).

print_fb(1) :-
fizzbuzz(Fizzbuzz, 1),
write(Fizzbuzz), nl, !.

print_fb(X) :-
Y is X - 1,
print_fb(Y),
fizzbuzz(Fizzbuzz, X),
write(Fizzbuzz), nl, !.

goal :- print_fb(100), halt.


I don't know, why, maybe it must have something with declarative nature of those languages.
>>
File: akari298.gif (357KB, 320x180px) Image search: [Google]
akari298.gif
357KB, 320x180px
Friendly reminder that you can practice principles of functional programming in any language and pure stateless programming is a meme.
>>
can somebody do fizzbuzz in apl
>>
>no ocaml
Just fuck off faggot
>>
>>58141517
Purity is not a meme but stateless is (mostly). The fact is you can write a stateless, pure function and call it in a stateful (also pure) way in a non-shit language.
>>
>>58141517
>Friendly reminder that you can practice principles of functional programming in any language
Sure, but some languages lend themselves to FP much more than others. I wouldn't want to hack together a pure, functional program in C because that would be a waste of time.
>>
>>58141517
>>58141765
This is called return value optimization, to maybe ring some bells.
>>
>>58141545
Provide some good resources for OCaml, you are welcome.
>>
>common lisp
>functional
yeah if your language can only construct functional manners through hacks, then it's not functional
>>
File: 1443604195353.jpg (125KB, 800x720px) Image search: [Google]
1443604195353.jpg
125KB, 800x720px
>>58141517
You know, there are tools for specific tasks.
Like you use hammer to nail, but not microscopes, you use functional languages to program FP-way efficiently.
Yes, there are FP tools in non-FP languages, but they are complementary to those languages, but not the principles those languages are built upon.
>>
File: GJIuBLq.png (305KB, 640x974px) Image search: [Google]
GJIuBLq.png
305KB, 640x974px
who /readingsicp/ here
>>
I'll be adding those:

>The Seasoned Schemer (intermediate)
>The Scheme Programming Language by Kent Dybvig (intro)
>Realm of Racket (intro)
>>
>>58142052
No, it's a meme book that's worthless, won't teach you anything good that can be applied to the real world and you could be reading something that will actually have applications.

Read a practical book on your language of choice.
Read a book on systems engineering.
Read a book on project management.
Read a book on the topic that you're interested in.
Hell go to sad panda and jack off.

There is literally no reason to read structure and interpretation of computer memes
>>
File: 82343203_9a96ff98b1_z.jpg (59KB, 500x375px) Image search: [Google]
82343203_9a96ff98b1_z.jpg
59KB, 500x375px
>>58142365
Abelson and Sussman had given up on reading SICP 20 years ago, actually.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  We're doomed.
>>
>>58141598
I have to agree that, while the first few posts in this thread were shameless trolling, I've seen more interesting Haskell posted than weeks of /dpt/s.
>>
>>58141537
Here's what Rosetta Code has on APL Fizzbuzz:
⎕IO←0
(L,'Fizz' 'Buzz' 'FizzBuzz')[¯1+(L×W=0)+W←(100×~0=W)+W←⊃+/1 2×0=3 5|⊂L←1+⍳100]

Hell, it seems I have not enough characters for this language.
>>
>>58142440
Exactly.
The book is not bad but it's not useful. It's like reading a very hard puzzle book.

The problem with the book is its length, there are so many good books one could be reading instead like
>gang of four
>code complete
>concrete mathematics
>mythical man month
>rapid development
And so on. Never mind books on specific languages or topics one is interested on.

All those books will give you something real that SICP will not.
>>
>>58142593
The modern equivalent to APL is called J:
https://www.rosettacode.org/wiki/FizzBuzz#J
>>
>>58142614
Could you spoonfeed me on J and APL? I can't even think why these languages were created in the first place.
>>
File: expr.png (7KB, 218x105px) Image search: [Google]
expr.png
7KB, 218x105px
>>58142643
APL was one of the first languages ever made (and stands for literally “a programming language”), next to stuff like FORTRAN. It was a time when computers weren't widespread at all, but the thing of universities and used highly specialized hardware and single-purpose software (this predades operating systems).

APL machines in particular had special keyboards designed solely for them. The goal was to make mathematical computation easier. It was designed for mathematicians.

APL was designed for interactive mathematical queries, and suported mathematical constructs such as matrices and vectors natively. Many of the symbols come straight from mathematics.

Basically, an APL expression like
m ← +/(3+⍳4)
is the notational equivalent of pic related. It's not really designed for “general purpose” programming, and it's certainly not designed around any modern concepts of what we expect programming languages to be.

J is basically a fork of APL that replaces the difficult-to-input characters by sequences of ASCII characters. It has no real value except novelty / education / fun.
>>
>>58142643
APL was the 70s' and early 80s' MATLAB. It had some graphing capabilities and was good for analyzing data.
>>
>>58142052
I'm working through SICP right now, but I don't think that image is entirely accurate. For one, I am using the HTML version on MIT's website. I prefer that to print. Second, the video lectures are with HP employess, not MIT students. Third, the material is difficult. It is doable, but difficult.
>>
>>58142365
>No, it's a meme book that's worthless,

And specifically the reason it's worthless is because of its truly bizarre order of presenting topics -- an ordering that's totally out of touch with what's going on in actual computer science classrooms.

For example, it starts right out in chapter 1 by jumping into recursion and recursive tree algorithms. A vast majority of computer science faculty know that you can't just walk into an introductory programming class and on the first week show the students how Ackermann's function works, and how to recursively calculate the nth Fibonacci number in log n time using a clever tree-walking approach. For this reason, the book is pretty much totally ignored by a vast majority of computer science departments.

Here's an example footnote from chapter 1, that shows you just how utterly ignorant they are about the concept of communicating effectively to a student in an introductory programming course:

"31 Tail recursion has long been known as a compiler optimization trick. A coherent semantic basis for tail recursion was provided by Carl Hewitt (1977), who explained it in terms of the ``message-passing'' model of computation that we shall discuss in chapter 3. Inspired by this, Gerald Jay Sussman and Guy Lewis Steele Jr. (see Steele 1975) constructed a tail-recursive interpreter for Scheme. Steele later showed how tail recursion is a consequence of the natural way to compile procedure calls (Steele 1977). "
>>
I'd agree with all the "SICP = meme" posts. How to Design Programs is a much better book to learn programming from scratch, and only after that would I suggest moving onto SICP.

I've heard good things about Programming and Programming Languages (http://papl.cs.brown.edu/) too but not got around to reading it. It uses a weird language though but the author argues that it was designed and created purely for educational purposes. To me, that sounds like a dumb idea and students but should be taught a real language, but what the fuck do I know?
>>
>>58142927
>>58143031
SICP is not intended for total beginners. It was a textbook for university freshmen. The students in the course would likely already have taken a calculus class (hence the calculus exercises in the book), and even some kind of programming or computer science class. We did similar recursive exercises in high school.
>>
>>58143136
Students in video course are HP workers.
>>
>>58143190
Yup. Mentioned that above.
>>
>>58143214
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/video-lectures/
>>
(defun fizzbuzz (n &aux (f (mod n 5))
(g (mod n 3)))
(cond ((= f g 0) 'fizzbuzz)
((= g 0) 'fizz)
((= f 0) 'buzz)
(t n)))
>>
>>58143369
yeah those are the most disgusting pieces of shit haskell examples I've ever seen

nearly made me vomit
>>
fizzbuzz n = mapM (\i -> putStrLn $ fromMaybe (show i) (("Fizz" <$ guard (mod i 3 == 0)) <> ("Buzz" <$ guard (mod i 5 == 0)))) [1..n]
>>
>>58143452
absolutely disgusting. break that shit up and reorganize it, then we'll talk
>>
>>58143466
main = mapM putStrLn $ fizzbuzz 100

fizzbuzz n = map f [1..n] where
f i = fromMaybe (show i) $ (g "Fizz" 3 i) <> (g "Buzz" 5 i)
g s n i = s <$ guard (mod i n == 0)
>>
>>58143466
>>58143503
Just realized there are redundant parens.
main = mapM putStrLn $ fizzbuzz 100

fizzbuzz n = map f [1..n] where
f i = fromMaybe (show i) $ g "Fizz" 3 i <> g "Buzz" 5 i
g s n i = s <$ guard (mod i n == 0)
>>
File: haskell.png (754KB, 1920x1600px) Image search: [Google]
haskell.png
754KB, 1920x1600px
Haskell is CUTE and PURE!
>>
>>58142927
>People are stupid and don't like to put effort into things.
>>
>>58142927
What ever happened to learning about a topic you're curious about *before* going to university to study it further?

Why is it the norm that people expect to just waltz into a university with absolutely no prior knowledge on a subject and expect to be spoonfed?
>>
>>58143136
> SICP is not intended for total beginners.

This is true. But that does not change the fact that the ordering of the material in SICP is totally out of sync with the broad consensus about the most effective ordering for teaching it. It's no coincidence that most universities' computer science curricula have their topics arranged in roughly the same order. That ordering was developed by a broad consensus of computer science educators over a period of decades.

>>58144304
>What ever happened to learning about a topic you're curious about *before* going to university to study it further?

What ever happened to teachers trying to figure out how to best communicate technical material to students in a clear, straightforward manner that's carefully designed to make the material as easy for the students to learn as is feasible possible?

There is no fucking reason why any textbook needs to EVER be perceived as hard or challenging. If the author truly cares about explaining the material clearly, and has the communication skills to do so, any subject can be explained in a way that most of the students find easy and straightforward to learn. Unfortunately, not nearly enough authors care to develop that skill, and SICP is one of the most atrocious examples of that.

There are reasons why SICP has been rejected by a vast majority of universities for their computer science program. It's good to learn those reasons -- because that helps you understand how to write better textbooks.
>>
I'm trying to write my first Monad in haskell, but having trouble writing the >>= function. The monad computes basic boolean algebra. The idea is that a Token manipulates a stack [Bool] and passes the stack, and if the stack doesn't contain enough bools, it returns Invalid_t. I think my syntax is off but I can't get it to load into ghci.

data Token = True_t | False_t | Not_t | ... | Invalid_t

instance Monad Token where
Token stack >>= f = case t of
True_t -> f (True:stack)
False_t -> f (False:stack)
....
Invalid_t -> ???


Is this a good way of doing this? Should I be using Maybe instead?
>>
>>58144588
>There is no fucking reason why any textbook needs to EVER be perceived as hard or challenging.
Textbooks are only perceived as hard or challenging if you lack the prerequisites for understanding said textbook

Human time is finite, including that of the authors. If you can spend 70% of your time on novel content and 30% on refreshers and introductory fluff, you'll have more content than if you spend 70% of your time in introductory fluff and only 30% on novel content.

This is why you don't see books on category theory start by explaining to you the concept of addition and subtraction using pictographic examples. If they had to build up a lifetime of mathematical understanding first, how much category theory would they get done?

Btw, I'm not defending SICP; I'm just calling your argument terrible. “it's bad because it assumes prior knowledge” is nonsensical because you're always assuming prior knowledge. Heck, I'm assuming prior knowledge of the english language, why shouldn't I assume prior knowledge of what a fucking tail call is
>>
>>58144652
You shouldn't be trying a free monad as your first monad. Free monads are pretty advanced and are engineered from the ground up to be monads so they can crib the syntax.

For one, Token has no type parameter so it cannot be a monad.
>>
>>58144652
Kind error. ‘Token’ has kind * but ‘Monad’ requires something of kind
* -> *
>>
>>58144701
What if I did something like this?

data Token = true_t | false_t | ... | invalid_t
true_t, false_t, ..., invalid_t :: [Bool] -> Maybe [Bool]
true_t stack = Just (True:stack)
false_t stack = Just (False:stack)
...
invalid_t _ = Nothing


Would that be easier?
>>
>>58144887
Yes, and now you can combine them using fmap.
>>
File: 1480881313362.jpg (77KB, 488x429px) Image search: [Google]
1480881313362.jpg
77KB, 488x429px
>>58144927
Thanks bud
>>
>>58144954
Though you wouldn't have that Token definition anymore. You would have
type Token = [Bool] -> Maybe [Bool].


With RebindableSyntax you could do:
newtype Token = Token { runToken :: [Bool] -> Maybe [Bool] }

true_t :: Token
true_t = Token $ \stack -> Just (true : stack)
-- etc.

(>>) :: Token -> Token -> Token
t >> u = Token $ runToken u . runToken t

foo :: Token
foo = do
true_t
false_t
and_t
>>
>>58145010
please stop rebinding (>>)
>>
Does this look alright? I haven't got the hang of any fancy syntax just yet.

type Token = [Bool] -> Maybe [Bool]
true_t st = Just (True:st) :: Token
false_t st = Just (False:st) :: Token
... etc
>>
Oh hold on, It doesn't like the Token type declaration at the end.
>>
>>58145010
Btw, I'm very sure there was a really simple way to do “stack operations” like these using nothing but continuation passing style (?) and a bunch of appended function calls, but I don't remember the exact details.

(The source code basically looked like your do block but without the do and with an extra ‘E’ at the end or something)

I mean I can do it the brute force way by using a type class to construct the infinite type, but that's sort of lame, and I'm sure there was some ultra-elegant way I'm trying hard to remember. Maybe somebody else knows what I might be referring to?
>>
>>58145169
The
:: Token
you have there applies to the expression
Just (True:st)
, not the whole function.
>>
>>58145339
Got it, thanks. I'll just stick with the sticking the type sig of the tokens above it (even though it looks a bit tiresome to use 10 lines to type 10 variables)
>>
>>58142052
Reading Joy of Clojure the "cool" uncle in the lisp family.
>>
>>58145323
found it

type Stack = [Bool]
type Op t = Stack -> (Stack -> t) -> t

true_t, false_t :: Op t
true_t s k = k (True : s)
false_t s k = k (False : s)

and_t :: Op t
and_t (x:y:s) k = k $ (x && y) : s

go k = k []
stop s = s

foo :: Stack
foo = go
true_t
false_t
and_t
stop


extending this to support Maybe is left as an exercise to the reader
>>
>>58145415
forgot URL

http://alecb.me/blog/stack-language-ocaml
>>
>tfw Haskell is so close to your ideal language but the community is shit
>ridiculous need to invent a fucking 2 character symbol for every thing making code impossible to read
>language is indesicive so you have a million unofficial extensions in ghci which means 2 different projects are basically using 2 different languages
>stupidly clever and complicated solutions like backpack because String is still [Char] instead of solving it the simple way
>>
>>58145431
>language is indesicive so you have a million unofficial extensions
I think it's both a blessing and a curse. It basically goes to show that Haskell in practice is more of a research language than anything else. While you can use it in practice just fine, its main goal is still pushing the envelope of functional programming.

It needs a lot of time to mature and gain industry acceptance if it ever wants to be used at a larger scale in the real world (i.e. companies).
>>
>>58145662
>implying Haskell is pushing the envelope anymore
>>
Which functional language should I learn? I've looked into a bit of Haskell, but should I continue or pick another?
>>
>>58146589
That all depends. Do you like Haskell?
>>
>>58140826
write a function to return factors

factors :: Int -> [Int]
then
numFactors = length . factors


e.g.

factors n = filter (\x -> n `rem` x == 0) [1 .. n]
>>
>>58145431
>>58145662
>a million extensions
The majority has a common opinion on which ones to use though.
I think the issue is a lot of them haven't been standardised, hopefully they will be for Haskell 2020
>>
File: 1449803425405.jpg (21KB, 249x301px) Image search: [Google]
1449803425405.jpg
21KB, 249x301px
>>58141396
>The purest code is never written.
>>
>>58146811
>2016
>he still needs to write code
sad!
>>
Reminder that you can discuss functional programming in /dpt/ and you're more likely to get a reply.

>>58147118

>>58147118

>>58147118
>>
public class Fuckyou{
public Fuckyou(){
System.out.println("Hey fagz");
}
public static void main(String[] args){
new Fuckyou();
}
}
>>
>>58147467
You should probably move the println to the main method. You don't really need a constructor for something like that.
>>
>>58147530
but that's not OOP at all
>>
>>58147467
in Haskell this is just

main = print "Hey fagz"
>>
>>58147549
If you wanted to OO more, you should have an interface of FuckYou and have a "class Thing<FuckYou>" that uses them in some way, that way your output isn't bound to a specific implementation.
>>
>>58147615
This is also good for testing, because you can then test both sides of the interface.

This kind of testing absolutely everywhere is both great since you can usually run your entire test suite in less than a second, and is important if you want to refactor things nontrivially later to make sure you satisfy the interface's contract.
>>
>>58147643
Yeah, this lets you avoid integration tests. That's a good thing because integration testing is horrible for OO systems. (Actually, integration tests are horribly inefficient in general)

Avoid those like the plague by making sure your OO is separated enough, and make sure your designs use interfaces for everything. Otherwise you will inevitably find bugs almost any time you want to add some new functionality that isn't super-basic.

Honestly, it's kind if a pain. I think a lot of us here like functional because it lets us avoid this headache.
>>
>>58147615
A generic isn't needed either. Just make sure the interface defines methods that accept FuckYou and you should be fine.
>>
>>58146811
Written code changes the state of the Universe.
>>
>>58147736
The more you can do with the least amount of changes, the better.
>>
>>58147736
>implying a new Universe isn't created whenever anything happens
>>
>>58147763
Well, it is, but most of the new universe is shared with the old universe. Otherwise that would be really, really expensive.
>>
>>58147763
Ah yes, the persistent universe theory.
>>
>>58147771
Memory is cheap now, we can handle the whole new universe.
>>
Professional OCaml coder here. >tfw
>>
>>58148766
Why haven't Haskell and OCaml been brought together yet?
>>
let () =
print_char '\007';
flush stdout
;;
>>
>>58142017
>You know, there are tools for specific tasks.
but there is no task that demands a programming language that is primarily focused on functional programming.
>>
>>58142052
I watched all the lectures on youtube, does that count?
>>
>>58148848
Language manipulation (ie. compilers).
>>
>>58148848
Functional programming is the basis of all good programming.
>>
>>58148848
Highly parallel operations. Infact Scala is going beyond threads and cores and into distributed computing in a principled way with Scala spores.
>>
>>58141835
Real World Ocaml
https://realworldocaml.org/
>>
>>58149178
I'll be adding this.
>>
>>58141396
Functions are first class citizens in python. Can python be considered as a FP language?
>>
>>58149209
It can be considered a shit language in which you can do -


actually aren't closures fucked in python?

guess not faggot
>>
>>58141396
Is functional programming a meme?
>>
>>58149209
It's not designed to be a functional language, and competence of the creator in FP is to be questioned.
http://www.artima.com/weblogs/viewpost.jsp?thread=147358
>>
>>58149209
Despite the name "Functional Programming", FP means more than having functions as first class citizens.

Nowadays your language needs to implement at least a few of these to be considered a FP language: https://medium.com/@jlouis666/on-functional-programming-df28cc9078de#.9d52x610l
>>
>>58146196
>implying it isn't
Have you seen a list of GHC 8.0's new features?

https://ghc.haskell.org/trac/ghc/blog/ghc-8.0.1-released

Haskell is still very much evolving, and it's going in directions I would never have predicted. TypeInType pretty much blows my mind. It's basically inching closer and closer to simulating full dependent types without requiring an actual dependent type system, which is a major breakthrough.
>>
>>58146196
Haskell was created as a common language for introducing PLT ideas without everyone having to define their own language in each of their papers, it will continue to serve its academic purpose.

Obviously a few of those ideas will prop up and actually be used in the real world.
>>
>>58149298
no, it's THE meme
>>
>>58146727
>The majority has a common opinion on which ones to use though.
Personally I consider Haskell to have all extensions turned on, except for the “dangerous” ones.

When I think of writing a Haskell program, I think in terms of the Haskell superlanguage with all extensions - and then I just keep adding whatever bullshit pragmas GHC tells me to add so it will compile my code.
>>
>>58147134
Reminder that you can discuss functional programming in /b/ and you're more likely to get a reply.
>>
>>58149209
To me, functional programming implies algebraic data types and pattern matching.

Does python have pattern matching?
>>
>>58149387
basically this
which do you consider dangerous?
UndecidableInstances ?
>>
>>58149399
https://github.com/Suor/patterns
>>
>>58149411
UndecidableInstances can be slightly dangerous depending on the circumstances. If you're trying to use the type system to prove your code is correct, undecidable instances can invalidate your proof.

That said, Haskell isn't exactly the best language for that either way (because of undefined :: a), and UndefinedInstances in practice will just cause your compiler to hit a recursion limit, so they're no more dangerous than C++ templates
>>
>>58149426
cool but JESUS FUCKING CHRIST THAT EXAMPLe

I want to strangle all python programmers, how can you be this fucking bad. Jesus christ, the ‘factorial’ function is not supposed to do structural recursion over “arbitrary data types that the developer thought of at the time of writing the code”
>>
File: record synonyms.png (9KB, 563x130px) Image search: [Google]
record synonyms.png
9KB, 563x130px
>>58149354

>record pattern synonyms
>>
Is having two types with the same field name still a problem in GHC 8?

data Person = Person { name :: String }
data Cat = Cat { name :: String }
>>
No Idris?
>>
>>58150254
No, it's possible now
>>
>>58150353
Idris is allowed too, feel free to ask any questions but I don't know much idris so I'm not sure how much help I'll be
>>
>>58141545
OCaml is objectively shit though

(still, it's not as shitty as some of the "languages" in the OP)
>>
>>58144304
Back when a university education started costing five and even six figures. Are you surprised students want a lot in return when they're paying that much in tuition?
>>
>>58148791
Because OCaml is shit
>>
>>58150362
but awkward
>>
>>58150418
Modules and structural polymorphism are nice
>>
Are we only putting free resources in the OP? Or are paid ones welcome too?
>>
>>58150455
IMO you pay too high a price, OCaml lacks many goodies that Haskell has
>>
>>58150399
>Back when a university education started costing five and even six figures.
Oh right, I forgot you have to pay for university in burgerland
>>
>>58149340
kek his wishlist contradicts itself and no programming language on the planet actually satisfies it.
>>
>>58150475
This is why I said why can't we get both
>>
>>58150443
How so?
>>
>>58150516
x = Cat "adam"
y = Person "tiger"


bad
s1 = name x
s2 = name y


good
s1 = (name :: Cat -> String) x
s2 = (name :: Person -> String) y
>>
>>58150516
>>58150540
and this is despite the obvious

class Named a t where
name :: a -> t
updateName :: t -> a -> a

instance Named Cat String where
..
instance Named Person String where
..


good:
s1 = name x
s2 = name y
>>
>>58150500
It's not just in the US, in the UK a degree will set you back 27000 pounds these days, not including living costs.
>>
>>58150550
a completely misleading claim
>>
>>58150540
also good

s1 = name (x :: Cat)
s2 = name (y :: Person)


desu I don't know why it can't infer the first one. It should be no more difficult than type class instance selection
>>
>>58150561
they should instead have had it directly translate into a type class, possibly even something we could use rebindable syntax with.

then we could even be parametric over it as a constraint
>>
>>58150558
How so?
>>
>>58150464
Free are preferable.
What kind of payment are you talking about? If that's some subscription or onlice courses with your personal instructor™, I doubt it should have a place.
Still, what would you want to add?
>>
>>58150570
you know how
>>
>>58150571
I was thinking books that you can buy, things with a one-off cost.

>>58150572
I don't.

Tuition fees are generally 9k per year in the UK, right? And not all students qualify for grants, they have to take out loans or put their hand in their (or more likely their parents') pocket.
>>
>>58150547
Yeah that's sort of awkward. I wonder why that limitation is in place. GHC is obviously powerful enough to resolve arbitrary instances like these, since you can write e.g.

class Has (name :: Symbol) a where
type FieldType name a :: *
get :: a -> FieldType a

type F name = a -> FieldType name a


and now just trivially use
(get :: F "name")
instead of name.
>>
>>58150587
What percentage of students DON'T get their entire tuition paid for by the government, to be repaid at a maximum of 10% of their salary (above a certain amount) ?
>>
>>58150587
>I was thinking books that you can buy, things with a one-off cost.
You are welcome.
>>
>>58150607
That's still paying 9k per year. Do you think it's somehow magically different because the loan is from the government instead of a bank?

Also, losing 10% of your salary is really, really annoying. If somebody's trying to save so they can get a house, do you really think they're happy about having to fork that money over to the government, in addition to all the tax they pay, while those who were lucky enough to be born earlier pay nothing?
>>
>>58150678
>that's still paying 9k per year
No, it isn't. And boy, you must be so mad about having to pay 10% over a minimum for those degrees.
I know, I've got a great idea! Why not demand that everyone else in the country pay more to subsidise YOUR choice?

That was your first retarded thought.
The second was to blame the government for increasing the limits, and not the universities for immediately tripling their prices.

But after all, you're just a student. A dumb, easily manipulated political sheep.
>>
Is it true that Scala is the easiest FP language to get a job with? I feel like working with dynamically typed/object-oriented/enterprise poo-code all day is gradually turning me into a retarded webdev poo-programmer.
>>
>>58150789
Probably yes.
>>
>>58150789
Scala is probably the worst mainstream FP language, it is pretty mainstream and has jobs.
Might be dying down, heard someone saying that, but I dunno.
>>
>>58150737
I graduated over a decade ago. My younger brother has to deal with this shit.

You really think not raising prices to the maximum allowed is a feasible option for universities? Like, I'm sure their teaching and resources are gonna be top-class if they amputate their funding.

I wouldn't mind the tuition increases if people who benefited from lower or no fees (who were effectively being subsidized by the UK taxpayer) when they studied had to cough up as well. Yes, that includes me. Happy to fork over the difference between what I paid and what my brother is paying if everyone else does too.
>>
>>58150737
Oh boy... Anyone that uses the term "sheep" automatically has their opinion discarded.
>>
>>58150808
>Scala is probably the worst mainstream FP language
Absolutely, but it doesn't seem like I'm going to get to write Haskell or OCaml professionally any time soon so I'm willing to live with it.
>>
Convince me to learn functional program as someone who has only ever done OOP
>>
Scala talks:
https://www.youtube.com/channel/UCc0j7uOItUDh7vEvPb-TeCg
>>
>>58150865
Wouldn't you like to never have to use a design pattern again?
>>
>>58150832
I'm not looking to convert student minded individuals.
They're too dumb, and just need to face reality and grow up.

>>58150825
>Happy to fork over the difference between what I paid and what my brother is paying if everyone else does too.
I'm sure the people that never went to university are happy to pay his bills, as well as the bills of thousands of students who (in far more than excess) drink and party and consume and fail and drop out (on someone else's dime).
>>
>>58150865
Why should I? Convince me to convince you
>>
>>58150865
You can choice between being called pajeet or being called hipster faggot. If you don't mind being liberal and promote lgbt, then go functional.
>>
>>58150865
Because it's different and you might learn something?

If you're so happy with OOP that you don't want to learn anything else then please stay away from FP, there's already too many of you retards infesting the community.
>>
>>58150881
>>58150912
Haskell shill defense force activated
>>
>>58150884
>I'm sure the people that never went to university are happy to pay his bills
I meant the people who went to university in the past and paid lower fees for it.

Regardless, the barely-sentient humanoids who never went to university should be happy to contribute towards the bills of students, because they enjoy the benefits of the work of university graduates every day.
>>
>>58150930
Face it Pajeet, you'll soon be obsolete
Out on your feet, back to shitting in the street
>>
>>58150942
I don't need to reply to this.

>>58150930
Can you give less obvious bait please?
>>
>>58150969
>t. barely-sentient humanoid
>>
>>58150953
I'm a Haskell programmer, but you fucks are the people giving the language a bad rep

seriously the community is so disgustingly toxic
>>
>>58150985
>toxic
In other words, you got buttblasted when you asked for help trying to do OOP in Haskell and got BTFO.
>>
>>58151004
I know more about Haskell than this board put together.

My problem is the people who think the language is holy or whatever, and keep trying to spread their cancer fucking everywhere. In general, fanatic followers of anything (e.g. linux) are fucking cancerous
>>
>>58150985
http://blog.tmorris.net/posts/how-to-find-thinking-people/index.html
>>
>>58151029
This is stupid advice.
>>
>>58151025
>I know more about Haskell than this board put together.
Evidently not, otherwise you wouldn't be getting so upset.
>>
>>58151036
Why? Would you get flustered by that little four-letter word?
>>
>>58149209
Sorry to say, but functional code is crippled so much in Python. Ruby or JavaScript are both miles more functional.
>>
>>58150985
>I'm a Haskell programmer, but
How to tell when someone's not a Haskell programmer.
>>
>>58151100
When your language loses to fucking JavaScript, it's time to retire it.
>>
>>58151025
>My problem is the people who think the language is holy or whatever
If the only languages you've seen before it are Java, C#, Python, or JS, then you could be forgiven for making that mistake.
>>
Why are Java/C# programmers so incapable of learning anything outside their dumbed-down languages and paradigm?
>>
What does /fpt/ think of Perl 6?

While it is not a functional language, it took a ridiculous amount of inspiration from Haskell and the original reference implementation was written in it. So it has all of the features to write nearly completely functional code.

Scroll past the imperative bits in here if you don't know what I mean: https://learnxinyminutes.com/docs/perl6/
>>
>>58151233
Why did anybody think this was a good idea?

Your language is dead, bro. End the fucking ego trip already. The world would have been a better place had you not made a new version of it.
>>
>>58151217
I think a lot of us ARE Java programmers who know good OO design well enough to prefer functional languages. For example, look at the responses to >>58147467
>>
>>58151273
Perl 6 is not Perl, nor is it my language. I just played around with Rakudo's REPL and was pretty okay with it.

This is why I was curious what others thought.
>>
>>58151140
It's a thing people do in general

Basically, anything you literally JUST started understanding/using is suddenly the best thing ever.

You can tell because anybody who has actually been exposed to a concept for several years will think that concept is shit. Especially in tech, but I would argue this is universally true.
>>
>>58151273
>>58151337
>Pattern matching
>Lazy infinite lists, list comprehension, and ranges
>High order everything
>Functions with arbitrary bounds outside of types
>Destructuring
>Types bound by mathematical rules
>Immutable stuffs
>Closures
>Isolated IO types if you want to isolate IO
>This lazy infinite Fibonacci array comprehension:
1, 1, *+* ... *;


I mean, all the tools are there, but I've never written anything useful in it.
>>
>>58151233
What is this even?
subset VeryBigInteger of Int where * > 500;


1, 1, -> $a, $b { $a + $b } ... *
>>
>>58151116
It looks like Python even gets stomped by Perl in the functional domain now.
>>
File: 1412215910683.jpg (219KB, 1280x720px) Image search: [Google]
1412215910683.jpg
219KB, 1280x720px
>>58151739
>looks for download to try it
>"docker pull rakudo"
>>
>>58151739
>
1, 1, *+* ... *;

wow, it's almost like I'm writing APL
>>
>>58152008
>docker
echo 'ALL ALL=(root) NOPASSWD: ALL' >> /etc/sudoers
>>
>>58152008
These errors are arsenal-tier
>>
>>58152459
>===SORRY!===
So cute.
>>
>>58152459
>literally an arrow pointing where the problem is
>>
>>58152490
Not as cute as

$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/nand/.ghci
λ data Foo where Foo :: Show a => a -> Foo
λ :t let Foo s = Foo () in show s

<interactive>:1:5: error:
• My brain just exploded
I can't handle pattern bindings for existential or GADT data constructors.
Instead, use a case-expression, or do-notation, to unpack the constructor.
• In the pattern: Foo s
In a pattern binding: Foo s = Foo ()
In the expression: let Foo s = Foo () in show s
λ
>>
>>58152503
Just like 4chan
>>
>>58141396
Why no scala?
>>
>>58153314
Scala is not FP
>>
>>58153314
No resources provided yet.
>>
>>58153314
>why no Java?
>>
>>58142643
APL has a steep learning curve, it needs a special type of input to write anything in it, and it's implementations (Dyalog APL, proprietary and GNU APL) are barely ported to any system at all.
That said, when you get used to it, it can be really fun and it forces you to think in a different way, instead of using traditional control structures such as loops, you spread all your information on multidimensional arrays, and "bend" them with some operations to get the result you want.
>>
>>58149354
>It's basically inching closer and closer to simulating full dependent types without requiring an actual dependent type system, which is a major breakthrough.
Except it still doesn't have lambdas at the type level or anything like that. I don't see the benefit in almost having dependent types with a zillion language extensions when you can encompass all of these language extensions by giving the language dependent types in the first place.
>>
>>58153786
This. Haskell is a swell language and all, but dependent types need to be built in a language from the ground up.
>>
>>58153794
And it's not like this is still really cutting edge stuff. Cutting edge is making homotopy type theory into a programming language or using ornaments/colours for code reuse.
>>
>>58142052
>>58142365
I'm going to tell you that you are wrong, and that I watched the first 18 minutes of the lecture 1A for an hour with three pages of notes. I work in the real world and I was actually able to devise great strategies from the lecture.
You have to read between the lines, pause, and digest exactly what he is saying in order to benefit.

I couldn't give a shit about LISP but the lecture from an engineering perspective is dope.
>>
>>58153818
>colors
seems like you made a typo, anon
>>
>>58141517
>he doesn't know about monads
>>
Can you guys redpill me on indexed functors, applicatives, monads, comonads, and arrows?
>>
>>58155482
Indexed functors are more than regular functors
Do you want to learn regular functors/applicatives/arrows/monads/comonads first?
>>
>>58155522
I know functors, applicatives, monads, and comonads already.
>>
https://www.youtube.com/watch?v=uqsZa36Io2M
>>
File: wire defusal problem.png (277KB, 2780x860px) Image search: [Google]
wire defusal problem.png
277KB, 2780x860px
>>58155592
Arrows are slightly more general than monads.
I think they're equivalent to applicatives?
They don't see much use

Indexed types are quite cool
Pic related is an example.
Rather than 1 type parameter, you have additional type parameters that change.
Monadic sequencing:
m a -> (a -> m b) -> m b
becomes
m i j a -> (a -> m j k b) -> m i k b
(similarly for comonads, applicatives)

these two parameters are sort of like an "input state" and an "output state"
one example is like this - the type changing state monad

State s a becomes IState i j a

Where i is the initial type of the computation, and j is the final type - i.e. the state can change type during the computation, assuming everything matches up.
if you look at the bind type
m i j a -> (a -> m j k b) -> m i k b
Or simple sequencing (non-functor):
f i j -> f j k -> f i k

i j ... j k ... i k
(i -> j) + (j -> k) = (i -> k)

another example would be having a kind of state monad where you have an open door or a closed door
data Door = Open | Closed
data DoorM i j where
open :: DoorM Closed Open
close :: DoorM Open Closed
sequence :: DoorM i j -> DoorM j k -> DoorM i k
...
-- (DataKinds)
-- (we can then use rebindablesyntax and do (>>) = Sequence, like in the pic)

if we look back at our sequencing type

sequence :: DoorM i j -> DoorM j k -> DoorM i k

and try

open `sequence` open[/close]
we'll get an error, because the second open assumes that the initial state is closed.
but since we just opened the door, the state is opened - so we can't sequence these

by using all sorts of stuff like this, you can make lots of complicated controls of effects in a type system.
for example, you could have file IO, with a "file open | file closed" state, and your runFile only runs operations that assume the file is closed and finish with it closed

In the picture, the state is which wire has been cut, and which wire is being cut
>>
>>58155770
>open[/close]
heh
>>
>>58155770
Thanks fammy, looks very interesting, will try to get my head around everything you posted.
>>
>>58155770
so in the simple examples I give, they aren't functors or applicatives or monads, but they're indexed and have a notion of sequence (they're like indexed semigroups i guess)
most of them could be extended to be indexed monads

indexed state is an example

>>58155804
ironically

data CodeBlock = Open | Closed
data Post i j where
code :: Post Closed Open
text :: String -> Post i i
slashCode :: Post Open Closed
Sequence :: Post i j -> Post j k -> Post i k

submitPost :: Post Closed Closed -> IO ()
submitPost = undefined -- todo

(>>) = Sequence

post1 = do
code
text "asdf"
slashCode

post2 = do
code
text "asdf"
-- slashCode


main = do
submitPost post1
submitPost post2 -- type error!
>>
>>58155482
indexed X is basically like adding a category on top of that structure

so like uh, instead of

<*> :: f (a -> b) -> f a -> f b


you get

<*> :: f i j (a -> b) -> f j k a -> f i k b


One of the neat things about indexed monads etc. is that the types are so rigid that it's almost impossible to construct an invalid instance. So it has some use in writing regular (non-indexed) monad instances

The primary motivating example would be something like a state monad in which you can modify the type of the state inside a monad computation

put :: a -> IxState x a ()
get :: IxState a a a

modify :: (a -> b) -> IxState a b ()
>>
>>58155770
>we can then use rebindablesyntax and do (>>)
are you that shitter who keeps rebinding (>>) ?
>>
>>58156143
you know it :^)
>>
>>58156153
I'm pretty sure you could just use an actual monad for your door example
>>
>>58156194
No, you couldn't, they're different types.
You couldn't use regular monad do-notation.

For example, in the indexed state monad, the type of the state changes.
But State Int x and State Float x are different monads.

The type classes are overly limiting, and the syntax should be loosened
>>
>>58156240
>No, you couldn't, they're different types.
not unmodified obviously
>>
>>58156272
No, look
Do-notation wants very specific things

I mean look at my DoorM type - it's not even a monad, or an applicative.
But it can be sequenced.

(>>) in Haskell has type
f a -> f b -> f b


What if I want
a -> b -> c
?


F i j -> F j k -> F i k
If i j and k are all different, then this is similar to
a -> b -> c
>>
>>58156313
>Do-notation wants very specific things
Sorry, I meant assuming do notation worked for IxMonads, which it obviously doesn't (nvm)
>>
>>58156349
and this is why you need to rebind it

But even if you rebound it for IxMonads, then it wouldn't work for regular monads

maybe with polykinds?
>>
>>58156405
>>58156349
example of my construction, because I had fun writing it

{-# LANGUAGE GADTs, KindSignatures, DataKinds, PolyKinds #-}

import Control.Monad.Indexed

-- code block base functor

data CodeBlock = Open | Closed
data PostF (i :: CodeBlock) (j :: CodeBlock) :: * -> * where
Code :: f -> PostF Closed Open f
SlashCode :: f -> PostF Open Closed f
Text :: String -> f -> PostF i i f

instance IxFunctor PostF where
imap f (Code r) = Code (f r)
imap f (SlashCode r) = SlashCode (f r)
imap f (Text s r) = Text s (f r)

-- indexed free monad

data IxFree (f :: k -> k -> * -> *) (i :: k) (j :: k) :: * -> * where
IxPure :: a -> IxFree f i i a
IxFree :: f i j (IxFree f j k a) -> IxFree f i k a

instance IxFunctor f => IxFunctor (IxFree f) where
imap f (IxPure a) = IxPure $ f a
imap f (IxFree g) = IxFree $ imap (imap f) g

instance IxFunctor f => IxPointed (IxFree f) where
ireturn a = IxPure a

instance IxFunctor f => IxApplicative (IxFree f) where
iap = iapIxMonad

instance IxFunctor f => IxMonad (IxFree f) where
ibind f (IxPure a) = f a
ibind f (IxFree g) = IxFree $ imap (ibind f) g

-- example

type PostM = IxFree PostF

code, slashCode :: PostM Closed Open ()
code = IxFree . Code $ IxPure ()
slashCode = IxFree . SlashCode $ IxPure ()

text :: String -> PostM Closed Open ()
text s = IxFree . Text f $ IxPure ()
>>
oh i didn't mention, in >>58156589 's post
>f i j (IxFree f j k a) -> IxFree f i k a

this is join, another way of describing a monad is with join rather than bind
>>
>>58156589
you accidentally give code and slashCode the same type indices (Closed Open, slashCode should be Open Closed)
>>
>>58156642
can I define my monads via the adjunction counit?
>>
>>58156668
oh right. Maybe if I had actually type checked the damn thing I wouldn't have made that mistake :^)
>>
>>58156721
http://www.stephendiehl.com/posts/adjunctions.html
>>
what's a better code style for Java lambdas?

(unit) -> unit.isAlive()

or
unit -> unit.isAlive()


I'm aiming for consistency here. is it possible to have something like:
(x, y) -> x.equals(y)

to make the parenthesis have a use for consistency?
>>
File: bullshit.jpg (76KB, 740x735px) Image search: [Google]
bullshit.jpg
76KB, 740x735px
>>58142052
>Wrote a a differentiation algorithm in scheme to help with freshman calculus project
>Get to section in SICP with their differentiation algorithm and they actually wrote one that's legible and scales well featurewise
Seriously, what the fuck was I thinking with this bullshit lmfao
>>
>>58156848
(unit) -> seems redundant to me

>>58156883
this would be much nicer in haskell
i assume

because i cant fucking read it
>>
cant decide haskell vs lisp :/
1st functional lang im gonna learn
>>
>>58156900
Haskell. Look at >>58156883 for lisp.
>>
>>58156895
>>58156908
lolno I just wrote it in a really fucking terrible fashion

lisp is beautiful when you don't write it in a way that's retarded
>>
>>58156848
I don't bother with parens for single arguments since these are usually the only argument anyway. (And even when they aren't, parenthesis seem like needless noise because lambdas really stand out as it is I find)
>>
>>58156933
You could write auto differentiation in haskell
>>
File: Capture.png (242KB, 453x595px) Image search: [Google]
Capture.png
242KB, 453x595px
>>58156895
>(unit) -> seems redundant to me
I know that I can simplify it by using Unit::isAlive
but how about complex predicates like
(unit) -> unit.isAlive() && unit.fullHitPoints()

It's not possible to do it with the "::" style

I'm more concerned on the complex predicates like
(unit) -> unit.isAlive() && unit.fullHitPoints()


So if something like
(first, second) -> first.equals(second) && first.greaterThan(second)
is possible (2 params on a predicate), then I would stick to the parenthesis even for single params
>>
>>58156883
Holy hideous. Please don't write Lisp like that, I don't care if a book says to. Manage your nesting.
>>
>>58156962
I meant the ( and )
You could write a function "both"

in Haskell it would have the type
(a -> Bool) -> (a -> Bool) -> a -> Bool

it would be something like this in Java

(f, g) -> (a -> f a && g a)

So you give it two functions and it produces a new function that &&s the result of those functions
>>
>>58156750
yeah but like

does this work for anything other than the trivial State adjunction
>>
>>58156976
Oh no, when I wrote that I was just doing it the quick and dirty way lol.

I keep it on my hard drive as an example of how terrible lisp code that works looks.
>>
Why are graphs a datastructure you always have to do by hand every time?
>>
File: events.jpg (99KB, 1088x623px) Image search: [Google]
events.jpg
99KB, 1088x623px
What are your thoughts on event-log databases?

They basically consist of an append-only stack of events and a collection of read-only models that are generated by folding over the events.
>>
>>58157055
Guava is a Java library that provides a very good graph support
https://github.com/google/guava/wiki/GraphsExplained
>>
>>58142052
Motherfucker where can you get SICP for 10 dollars I can only find it for 40 plus on amazon and MIT Press...
>>
>>58156979
The Predicate interface alreadty has the "and" function. Ideally, you would do it like:
Unit::isAlive.and(Unit::hasFullHitPoints);

But I think you need to cast it, like:
((Predicate<Unit>) Unit::isAlive).and(Unit::hasFullHitPoints);

To me it's cleaner to just do
unit -> unit.isAlive() && unit.hasFullHitPoints()
>>
>>58141396
I think you should link to this http://elixir-lang.org/learning.html for Elixir.
>>
>>58157055
import igraph
>>
>>58157242
I'll be adding this.
>>
>>58156405
Hmm, I was trying to explore ways of making a “super monad” that works for both regular monads and indexed monads, but I'm sort of stuck

I got as far as

{-# LANGUAGE TypeInType, TypeFamilies, PolyKinds, RankNTypes, TypeOperators, GADTs #-}

import Data.Kind

-- Polykinded arrows

class SuperMonad m where
type Arr m :: k -> k -> *
iret :: Arr m a (m a)
ibind :: Arr m a (m b) -> Arr m (m a) (m b)

-- Classic monads

instance SuperMonad Maybe where
type Arr Maybe = (->)
iret = return
ibind = (=<<)

-- McBride indexed monads

newtype IxIdentity a i = IxIdentity (a i)

newtype (~>) a b = IxA (forall i. a i -> b i)

instance SuperMonad IxIdentity where
type Arr IxIdentity = (~>)
iret = IxA $ \a -> IxIdentity a
ibind (IxA f) = IxA $ \(IxIdentity ai) -> f ai


but I'm having trouble working with the mcbridge representation of indexed monads, and the lack of real type functions means I need IxA wrapping/unwrapping everywhere (ugh)
>>
>>58157218
(| isAlive && hasFullHitPoints |)


your language needs idiom brackets badly
>>
We used to have a Lisp general on /g/. It ran off to another site. Will /fpt/ do the same, or stay?
>>
Looked through the Little Schemer.
The book is nice and all, but I don't get such a manner of presenting the material.
Looks like I'm not completely novice in Scheme.
>>
>>58157972
I was wondering what happened to those threads. They were fun.
>>
>>58157972
> another site
What site?
>>
>>58158168
Likely lainchan. 4chan's cyberpunk kid cousin.
>>
>>58158155
>>58158168

It's on lainchan's /lam/ board.
>>
>>58158314
>>58158490
Thanks, never heard of it.
>>
>>58158490
You are not a girl and will never be.
>>
File: Ruby_Design.jpg (66KB, 600x300px) Image search: [Google]
Ruby_Design.jpg
66KB, 600x300px
>>58159578
What's that about..?
>>
>>58158084
Don't be fooled by the childish drawings and 'jelly stains' pages.

The Little Schemer literally changes your thinking to be recursive. No joke.

The Seasoned Schemer is about continuations and functions, you do both with pen and paper no computer needed.

If you can manage those 2 then check out An Introduction to Functional Programming Through Lambda Calculus which will tell you all you need to know about Functional programming. It's a great book.

Why functional programming? Mainly because of state, so you can guarantee correctness, program up contracts, prove programs with Coq and other utilities ect.

I also took a great course at CMU about distributed programming using functional languages, MIT did the same thing called "The Art of The Propagator" by Sussman check that out sometime.
>>
>>58157215
You can sometimes find the first version on Abe Books, which is just as good as the second version.

instead of SICP you can also read Lisp in Small Pieces, it's the same thing (but vastly more difficult if you haven't already done SICP). Also EoPL (Essentials of Programming Languages by Friedman).
>>
>>58148848
anything to do with calculus is going to be much more intuitive in an FP language
>>
>>58157822
Kind families?
>>
File: 1482618565908.jpg (72KB, 806x711px) Image search: [Google]
1482618565908.jpg
72KB, 806x711px
Merry Christmas /fpt/!
>>
File: IMG_20161117_155417.png (47KB, 800x450px) Image search: [Google]
IMG_20161117_155417.png
47KB, 800x450px
>>58160622
Merry Christmas, anon..!
>>
>>58160773
Thank you!
>>
>>58156883
That looks like shit.

Looks like you wrote it in the Codecademy UI to top things off...
>>
>>58159578

Never claimed to be.

>>58160622
>>58160773

Merry Christmas, everyone.

let print_tree size =
let print_layer n =
let spaces = new string(' ', size - n)
let stars = new string('*', 2 * n + 1)
printfn "%s%s" spaces stars

let rec print_all n =
print_layer n
if n < size then print_all(n+1)

print_all 0
print_layer 0
>>
File: 1482604929810.jpg (80KB, 670x677px) Image search: [Google]
1482604929810.jpg
80KB, 670x677px
>>58161489
>rec
I never understood why can't it be implicit? It's a fucking functional PL, of course you're functions gonna be recursive and you gonna need tail recursion.
>>
>>58161489
Are you learning FP for Christmas?
that's pretty functional
>>
So i think i might pick up haskell as xmas present so where would i start? Preferably i want good book
>>
>>58162504
The wikibook (see OP) or the (not free but you might find pdf in off-site dpt archives) Haskell from first principles

what OS are you using?

ask here if you need help
>>
>>58162512
Thanks kind anon will check those out
Im using linux for work and windows for games, i have some experience with scheme but haskell looks interesting but kinda daunting.
>>
>>58159747
>An Introduction to Functional Programming Through Lambda Calculus
Does this book belong to any language?

>>58159782
I'll be adding those.
>>
>>58162528
If you use Windows, I recommend Haskell Platform and Atom.
On linux, I guess you can just get GHC and cabal directly

If you remember the lambda calculus, most of Haskell acts like that. Other than that, it's pretty much just types, type inference and pattern matching
>>
>>58162553
I started reading wikibook from begginer section and its clear and well written so far, hope it doesnt go awry.
I do somewhat remember lambda calclulus but i have forgoten much since i dont really need pure fp irl. I am comfy with recursions in imperative languages.
>>
>>58162553
Not him, but what should I learn about math to be comfortable in Haskell? Learning lambda calculus right now and it's going easier than I imagined since I didn't really pay attention to math in school.
>>
>>58162652
Not really, some stuff crops up to do with algebra, but it's entirely optional
>>
Can I do everything I can do in OOP in a purely functional manner? I don't know anything about functional programming yet.
>>
>>58163154
Yes
>>
>>58160563
Well I mean that's basically sort of what this is, isn't it? ‘type Arr’ lets the supermonad class abstract over the kind of the endofunctor the monad is constructed from.

For regular monads, it's (* -> *), and for mcbride indexed monads, it's (k -> *) -> (k -> *)
>>
I know that this is probably the worst question I could possibly ask in here, but I'm an outsider who is into some very basic web development and I'm starting to consider getting into software or game development, mostly because game development has been my dream but I also have a few ideas for programs that either don't exist or versions of things that do exist that cater more to my specific needs. What is the difference between functional programming and regular programming, is I guess what I'm trying to ask? Would I be better focusing on learning C++ and Python or should I be learning something like Haskell or Lisp? What are the pros and cons?
>>
>>58152008
bonus points if they demand that the user is part of the docker group. Might as well just run the whole thing with root privileges.
>>
File: monads.png (13KB, 300x225px) Image search: [Google]
monads.png
13KB, 300x225px
>>58166704
>>58167259
>>58168478
kinda sad desu
>>
File: 1481405173555.jpg (64KB, 300x300px) Image search: [Google]
1481405173555.jpg
64KB, 300x300px
>>58168503
I believe it's just Christmas time and anons have fun outside of 4chan.
Even /dpt/ got slow, so I think it's OK.
Too bad I'm not a competent functional programmer and can't answer properly, for example, to this anon: >>58164015
Merry Christmas!
>>
>>58164015
FP is oriented largely around the idea of functions as first class values, and because of its close relation with lambda calculus it normally ties in to type systems.
>>
>>58155412
They're talking about Haskell: 'colours' is the correct choice.
>>
>>58168875
This. Haskell is Her Majesty's Programming Language.
>>
What problem does the lens package solve? and do i need to understand it in order to become a better haskell programmer?
>>
>>58169427
>What problem does the lens package solve?
At the highest level; composition, reuse and abstraction of data structure access and similar concepts (getters/setters, constructors, traversals, folds, etc.)

It basically ties together a shitton of useful abstractions into a single unifying framework and lets you work with them, solving a number of real-world problems as a result.

For example, one of the issues in practice is that many containers and similar data types (like Text, ByteString, Vector, whatever) in Haskell are not real Functors/Traversals/whatever because they are not polymorphic enough, so as a result you have to re-implement a bunch of common combinators like “foldMap” on your custom data type.

With the help of the lens framework, it's possible for libraries like these to implement a single function (i.e. a ‘traversal’) for your data type and get all of the usual functions like foldMap etc. from the ‘lens’ library for free. This allows ‘lens’ to provide literal shittons of useful combinators that are reusable for pretty much any data type.

Furthermore, the fact that you can compose, combine, and transform these traversals, lenses, prisms etc. as first-class citizens buys you a lot of expressive power, which stuff like standard pattern matching in Haskell can't do. (For example and-patterns, or-patterns, patterns on existentials like SomeException, and more)

Control.Exception.Lens might be one of my particular examples of prisms being useful in practice, since they make catching specific exceptions in Haskell a billion times easier. For example, I can catch all exceptions related to some handle ‘h’ I have open by just writing
catching (_IOException.handle.only (Just h)) ...
>>
>>58164015
if you want to do software development you can probably get into a company that does functional programming as a main paradigm, for game development, no chance, you need to optimize everything fully there and just functional programming at it's core is against that (not the principles of it, but more what follows from the principles, since you aren't directly telling the processor what to do and when and how)
for game development C++ is pretty much industry standard

functional has no side effects, you cannot change the state of something, for example if you say a variable x is 5, you cannot later change it, if you have a list a -> b -> c you can't just change it to a -> d -> c, you have to make a new list that has it's second element as d
in functional programming you aim more to just "define" or "declare" what stuff is instead of explicitly telling the computer what to do and in what order, for example instead of using holding variables, swapping them around, comparing them for let's say quicksort (because of how often it's given as an example and how simple it is), you just say basically spell out the definition of it,
also you aim to heavily use functions that are widely accepted and very useful (like mapping, folding, filtering etc)
I might be talking bull here, but this is basically what I understand
also even if it not applicable to what you are working on in practice the functional style of programming changes your way of thinking and allows you to have a different view point
>>
>>58169538
>for pretty much any data type.
Including compositions of data structures, because you can just compose the underlying lenses and get a lens on the composition of the data structures (if that makes sense)

Like say I have a Map k [v] (map of keys to a list of values), I can compute the sum of all values by writing
sumOf (traverse.traverse)
, where
traverse.traverse
is a composition of the traversal for maps and the traversal for lists.

Or for example, say I have a
Map Int [v]
, I could get a list of all the values stored under even keys only by using
view (itraversed.indices even)
Thread posts: 281
Thread images: 23


[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.