/fpt/ - Functional Programming Thread

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: Resources:
>Erlang
learnyousomeerlang.com/content
>>Elixir
chimera.labs.oreilly.com/books/1234000001642/index.html
elixir-lang.org/learning.html
>F#
fsharp.org/learn
>Haskell
en.wikibooks.org/wiki/Haskell
0x0.st/pbp.pdf
>Lisps
>>Common Lisp
gigamonkeys.com/book
cs.cmu.edu/~dst/LispBook/book.pdf
Paul Graham's ANSI Common Lisp
On Lisp
Common Lisp Recipes
Land of Lisp
An Introduction to Functional Programming Through Lambda Calculus
>>Clojure
braveclojure.com/foreword/
The joy of Clojure
>>Scheme
SICP
Essentials of Programming Languages
How to Design Programs:
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
realworldocaml.org/
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
guide.elm-lang.org/
>>PureScript
purescript.org/learn/

Feel free to add more.

Other urls found in this thread:

arxiv.org/pdf/1012.4896
twitter.com/NSFWRedditImage

>Lisp girl
Please use a functional programming related anime image next time

Haskell was created because a lot of people had a lot of similar FP ideas that they kept incorporating into their own languages, but it's a lot better if it's consolidated into a single language.
Haskell's extensions make it a great place for language designers to experiment with new language constructs, typing mechanisms, syntax, etc.

Besides, it's by far the most popular purely functional language. Languages like OCaml just don't have that much going for it.

Homotopy type theory is always presented as Martin-Loef type theory, not as a pure type system.

Hott is an extension of MLTT. whats your point even?

>Maki
>ever
Karen best girl.
Exactly this picture made me create the first /fpt/ ever.

t. Creator, splitter and autist OP

Maki is holding the HoTT book but has a CoC overlay.

There are no closures in SKI calculus, and K is fundamental.

i.e., you don't need closures for 'const'. Closures are just environment capture. If you don't have a environment, you can't capture it.

So would it be more accurate to say that FP really needs some mechanism of partial application? That applies to both lambdas and combinators.

I thought you might be confusing closures with some other concept.

After using Eclipse for over a year I just recently switched to IntelliJ. Why didn't anybody tell me how it was THAT much better. Everything is so smooth I almost want to lick my screen.

I'm a different poster, I'm relating this back to .

Yeah, well you know what?
I made that image, so I made you who you are

Yup. You don't need closures for functional programming. Closures only come about as a result of first-class functions in combination with lexical scope.

While it's pretty hard (understatement) to claim a language is 'functional' without first-class functions, it's definitely possible to have dynamic (as opposed to static) scope.

That said, Joy is arguably a 'functional language' without first-class functions (which are instead emulated using quoting).

>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

post = "R" e
where
e = "E" e

>no Higher Order Perl

>So would it be more accurate to say that FP really needs some mechanism of partial application? That applies to both lambdas and combinators.
Hmm.. yes i think that's fair to say. to "have higher order functions" in a category sense is to have an isomorphism from HOM (a*b, c) to HOM(a, c^b); a way to go back and forth between curried and uncurried functions. there are platform dependent ways to do that, but, to say a function pointer is an exponential, you'd need some way of converting between (C*)(A,B) and (((C*)(B))*(A)), which you can't do with just standard C. You could use a different type for your exponential, and call 'higher order functions' not pointers to functions, but whatever 'partially applied functor' thing you've defined to do that instead.

>>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
These are actually true.

>CS 1 teacher worked at glaslow for several years
>world class haskell user
>offering a class on haskell
>its extraciricular meaning it wont count for credits

Should I go for it?

Who is it?

Yes
>its extraciricular meaning it wont count for credits
Who the hell cares.

Yes.
It's useful.
You can always tell employers you know it.

I want to go

Do you associate languages with colors? As in, when you see a bunch of code or even aren't looking at anything in particular but are just thinking in that language, does it have a certain tint for you?

For me it's

Lisp: Green
Haskell: Red
OCaml: Blue

Haskell: Red and White

Haskell is violet,
F-Sharp is blue.
Happy New Year,
user, I love you!

> () is string concatenation
> () is not an inequality check
your language a gay
that's just the logos nerd

Functional poorgramming is a joke.

Lisp is yellow, Haskell is blue (and grey and purple to lesser extents), OCaml I try not to think about.

> () is string concatenation
Oh dear, user, you have a long way to go.

She just told you she loves you and you call her a nerd?

() is just any binary associative operation on algebraic objects with a monoidal structure.

/= is best inequality. Go back to shitcaml you scrublord

Thanks OP for adding the second Haskell book. I've been trying to find it.

>not using FiraCode so != looks like ≠

What the hell is a FiraCode and why aren't you using emacs where you can configure anything to look like arbitrary unicode symbols?

...

a font

baka

Nat : Size => Type
zero : Nat i
succ : Nat i => Nat $i

Nat i = (x : {
zero : F .zero,
succ : [i' < i] => (m' : Nat i') => F (.succ m')
} => F x)
zero h = h.zero
succ m' h = h.succ m'

add : Nat i => Nat j => Nat #
add m n = m {
zero = m,
succ n' = .succ (add m n')
}

Thoughts?

Language?

One that does not exist yet. Also I fucked up:
add : Nat i => Nat j => Nat #
add m n = n {
zero = m,
succ n' = .succ (add m n')
}

What are you going to use to implement it?

Probably Haskell.

Yeeeeeahhbuddy.

Is it understandable enough? It uses self typing (x : F x) and sized types for termination checking but otherwise it's pretty standard.

sounds like a gay language, just use (++) for that

Trolled hard.

it seems pretty weird at first glance. like what is $i and #? I do like the pattern matching syntax a lot though

That's taken from the MiniAgda sized types syntax. $ is successor and # is infinity.
arxiv.org/pdf/1012.4896

Haskell: Green
Lisp: Yellow
OCaml, F#: Orange
Erlang: Red
-
C: Black

whatever happened to lainchan?

It's alive, and very, very*, slow.

*very

The Haskell thread is dead

I hope that I'm not late. If your language doesn't implement dependent type it's not a true fp.

Definition U : nat -> Type -> Type :=
fix f (n : nat) (T : Type) {struct n} : Type :=
match n with
| S n => T -> f n T
| 0 => T
end.

Definition sum : forall n : nat, U n nat :=
let f :=
fix f (n accu : nat) {struct n} : U n nat :=
match n with
| S n => fun x => f n (accu + x)
| 0 => accu
end in
fun n => f n 0.

Eval compute in sum 3 100 10 1.

Name a dependently typed language with at least mediocre performance.

I'll wait.

You can compile the rooster to caml if you want. So performance is not a problem.

ATS

>You can compile to caml so performance is not a problem

interesting. IMO the syntax is a bit too terse in that case, but idk how to make it more descriptive without making it Java
literally faster than any other FP language
Ur, ATS, F* possibly

>idk how to make it more descriptive without making it Java
You could upgrade to full Presburger arithmetic (so addition instead of just successor) and it would still be automatic.

You could go even further and use Nat (which is how you do advanced termination proofs in Agda) but it just gets ugly at that point.

Let me show you my dear blonde user:
Definition U : Type -> nat -> Type :=
fix f (T : Type) (n : nat) {struct n} : Type :=
match n with
| S n => T -> f T n
| 0 => T
end.

Definition sum :
forall (T : Type) (add : T -> T -> T) (zero : T) (n : nat), U T n :=
fun T add zero =>
let f :=
fix f (accu : T) (n : nat) {struct n} : U T n:=
match n with
| S n => fun x => f (add accu x) n
| 0 => accu
end in
fun n => f zero n.

Extraction Language Ocaml.
Extraction "sum.ml" sum.
After compiling that file the file sum.ml contains
type __ = Obj.t

type nat =
| O
| S of nat

type 'x u = __

(** val sum : ('a1 -> 'a1 -> 'a1) -> 'a1 -> nat -> 'a1 u **)

let sum add zero =
let f =
let rec f accu = function
| O -> accu
| S n0 -> (fun x -> Obj.magic f (Obj.magic add accu x) n0)
in f
in
(fun n -> Obj.magic f zero n)
So you can have fast proved code.

Abetter version with int instead of the slow type nat.
Definition U : Type -> nat -> Type :=
fix f (T : Type) (n : nat) {struct n} : Type :=
match n with
| S n => T -> f T n
| 0 => T
end.

Definition sum :
forall (T : Type) (add : T -> T -> T) (zero : T) (n : nat), U T n :=
fun T add zero =>
let f :=
fix f (accu : T) (n : nat) {struct n} : U T n:=
match n with
| S n => fun x => f (add accu x) n
| 0 => accu
end in
fun n => f zero n.

Extraction Language Ocaml.
Extract Inductive nat => "int"
[ "0" "(fun x -> x + 1)" ]
"(fun zero succ n -> if n = 0 then zero () else succ (pred n))".
Extraction "sum.ml" sum.

ew

Nice quads. What it's the first time you met dependent type?

It's the first time
no it isn't actually

it's the _th time i've seen such an ugly language

Coq is fucking hot.

Stop lying.

We don't share the same taste user.

My taste is right

Do any of you use functional programming professionally (i.e. get paid* for it)? I'm studying Scala** with the hope that it might get me out of enterprise code-monkey hell.

* Grad student stipends don't count.
** I know it's shit.

If I sit around at work and hack away with Haskell, I guess you could say that I'm getting paid to write it...

Yes.

Is there anyone else who does nothing but implement toy languages?

Bjarne Stroustrop

Me

I want to but I'm no good at it
The best I got was a broken dependently typed language

I didn't say I was any good at it either...

I seem to be making a postfix shell at the moment.

The entire interpreter is essentially foldM eval
I don't know if this is a good thing or a bad thing.

oh i made this, this was alright

My toy language is going to be [spoiler]object oriented without first class functions[/spoiler]

...

How to write highly-efficient Haskell code?

Use unboxed types everywhere

! ! ! !! ! ! !! !!!Vector ! !! {-# UNPACK #-}!! ! ! ! !

>!!
>(!!) :: [a] -> Int -> a
don't do this!

$! `seq` `seq` `seq` $!! ByteString `deepSeq` !!!! -XStrict !!!!!

However, I could create syntax sugar that generates objects with an apply() method. If you think about it, it'd be just about as functional as common lisp

{-# LANGUAGE Strict #-}

laziness is not good
fite me

post = "R" ++ repeat 'E'

Where do I find specifically where a function is in a module?

I am doing some gtk things with the graphics.ui.gtk module, and I prefer to explicitly import each function from where they live, so instead of just

import Graphics.UI.Gtk (mainGUI)


I'd prefer to have

import Graphics.UI.Gtk.General.General (mainGUI)


Now, I know where this one lives, but how can I quickly find where all the other functions in submodules are?

λ import Graphics.UI.Gtk
λ :info mainGUI
mainGUI :: IO () -- Defined in ‘Graphics.UI.Gtk.General.General’

Thanks friendo

With linear types, there are two kinds of conjunctions. The first is the multiplicative A*B, where you can project out both A and B like a normal pair. The second is the additive A&B, where you can only project out either the A or the B.

Record syntax {A, B, C, ...} is equivalent to A*B*C*..., pretty intuitive, but I would like to augment the syntax to allow certain fields to be mutually exclusive like with &. Because the records are to compile to structs, preserving order, I also don't want the syntax to force you to group the mutually exclusive fields. How do you think I can best express this in the syntax?

you should probably have different record syntax for each, but you can still "compose" them in the usual way;
{a::A,b::B,cd::[c::C|d::D]}
or visa versa
[a::A|b::B|cd::{c::C,d::D}]

what's the syntax you have in mind for committing to a particular linear field?

The issue with that is that it limits what you can do with the struct layout.

>what's the syntax you have in mind for committing to a particular linear field?
Just x.y.

>The second is the additive A&B, where you can only project out either the A or the B.
How is this different from a linear value of type Either a b?

With A&B the choice is made when it's eliminated, but with A+B the choice is made when it's constructed.

Why would the syntax limit the compiled implementation? Could the compiler notice "this is a linear product embedded in another product, INLINE ALL THE THINGS"?

Let's say I want the struct to be laid out like {A, B, C} but I want the A and the C to be mutually exclusive.