Live data from Hacker News

Functional Programming Patterns

slideshare.net

31–40 of 70 posts

Re: Functional Programming Patterns

#31
post #30
post #26

This is one of the reasons why Higher-Kinded Types are such a boon in the languages which have them. It allows you to translate "patterns" into straight-up libraries. This slideshow is good documentation for what the patterns are, but if you go use them in Haskell (e.g.) then you'll start to see that libraries are designed to completely contain that pattern and ensure compatibility between your use of it and others.…

> And to be fair, Haskell does not go tremendously far in this direction. The languages which will truly profit from this are still in gestation. What are examples of taking it further?

Generally what we're talking about is the ability to say something like "for all types X which satisfy a predicate P, we have this code". The ability to quantify over "all" types is a key property of dependently typed languages. Likewise, a lot of Haskell's ability to simulate DT languages comes from its ability to reason about HKTs.

In a DT language you have something called a Pi type which is a bit like a function type. An example would be to compare the types of two functions which, essentially, determine whether two integers are coprime

    coprime1 :      Int  ->      Int  -> Bool
    coprime2 : (a : Int) -> (b : Int) -> Maybe (IsCoPrime a b)
The important part is to look past the syntax and note that IsCoPrime is a type which depends upon the values of the first two arguments. Another way of reading this is as follows

    coprime3 : forall (a b : Int), Maybe (IsCoPrime a b)
this emphasizes that the type of `coprime3` is quantifying over all values in Int.

Then we can take this idea to the higher-kinded level by looking at the type of, say, monoids

     monoid : forall (A : Type), 
              { zero : A
              , plus : A -> A -> A
              , leftId  : forall (a : A), plus zero a = a
              , rightId : forall (a : A), plus a zero = a
              , assoc   : forall (a b c : A) , plus a (plus b c) =
                                               plus (plus a b) c
              }
Here we can see that the `forall` notation lets us freely abstract over "all types" just like we previously abstracted over "all values". This continues to work at every level. For instance, we can note that `monoid` above is "a type of types" or maybe a "specification" and we can abstract over all "all specifications" as well

    specProperty : forall (S : Type -> Type), P S

Re: Functional Programming Patterns

#32
post #27

Excellent presentation. Of the leading type safe functional languages (Haskell, F#, and OCaml) I find F# to be far and away the most accessible in terms of syntax and application. Writing Scala in my day job currently (which, for the most part, I quite enjoy) but can see jumping ship if Microsoft's move to Linux is successful. Being able to develop and deploy F# applications on Linux with full blown Type Providers an…

Loving learning #F for educational purpose on my spare time and I am loving it, any idea of which is the market for this language or for what you should be use it?

Check Skills Matter presentations.

It is being adopted in European financial and insurance sectors for data modelling.

Re: Functional Programming Patterns

#33
Ok, I'm sure the slides get better as they go on. But what the hell? The difference between the patterns that are compared and contrasted are... well, tenuous, at best.

Seriously, it gives off the impression not that these are going to be better patterns. But that someone simply has a bias against "patterns" as they are promoted in Java and then rails against it saying that they are going back to the root of the word patterns. Ignoring that this is the same path.

Re: Functional Programming Patterns

#34
post #24

Some guy almost 20 years ago argued, that if you end up with a bunch of "design patterns" then your language is not good enough.) http://norvig.com/design-patterns/design-patterns.pdf

16 of 23 patterns have qualitatively simpler implementation in Lisp or Dylan than in C++ for at least some uses of each pattern Things like this are literally why I switched from Python to Racket almost immediately once I discovered the latter. So much time spent fighting an imperative language to do something that seemed like it should just be easier in the first place.

Racket is an imperative language, as well. Right? Don't get me wrong, I love Racket. Just I don't think of it as !imperative.

I am also unconvinced that the imperative nature of many languages is the problem. Not sure what it is.

Re: Functional Programming Patterns

#35

I am currently taking EdX's Intro to Functional Programming mooc, taught by Erik Meijer (with his crazy shirts), which uses Haskell to teach functional programming concepts. I am wondering if there are any other good resources for teaching the functional programming paradigms. Anybody care to recommend me some resources? Also, I mainly work with Ruby and Javascript in my full time job. Currently, in school, I use Jav…

How are you finding the mooc? Can you recommend it?

Re: Functional Programming Patterns

#37

Excellent presentation. Of the leading type safe functional languages (Haskell, F#, and OCaml) I find F# to be far and away the most accessible in terms of syntax and application. Writing Scala in my day job currently (which, for the most part, I quite enjoy) but can see jumping ship if Microsoft's move to Linux is successful. Being able to develop and deploy F# applications on Linux with full blown Type Providers an…

Do you know if it is possible to use F# on windows without having to install several GB of crap? I'd like to be able to try it out, but the same way I would try any other language, install the compiler and try it out. All I can find is huge packages including visual studio and all kinds of other junk.

Re: Functional Programming Patterns

#38
post #31
post #30

Earlier quoted context omitted.

> And to be fair, Haskell does not go tremendously far in this direction. The languages which will truly profit from this are still in gestation. What are examples of taking it further?

Generally what we're talking about is the ability to say something like "for all types X which satisfy a predicate P, we have this code". The ability to quantify over "all" types is a key property of dependently typed languages. Likewise, a lot of Haskell's ability to simulate DT languages comes from its ability to reason about HKTs. In a DT language you have something called a Pi type which is a bit like a function…

Surely your monoid example should be a Sigma type (`exists`), not a Pi type (`forall`), since a monoid is a specification of data for a single type A, not for all types A. Indeed, the empty type has no monoid structure, so the Pi type you wrote down is necessarily empty.

Re: Functional Programming Patterns

#39

Excellent presentation. Of the leading type safe functional languages (Haskell, F#, and OCaml) I find F# to be far and away the most accessible in terms of syntax and application. Writing Scala in my day job currently (which, for the most part, I quite enjoy) but can see jumping ship if Microsoft's move to Linux is successful. Being able to develop and deploy F# applications on Linux with full blown Type Providers an…

Do you know if it is possible to use F# on windows without having to install several GB of crap? I'd like to be able to try it out, but the same way I would try any other language, install the compiler and try it out. All I can find is huge packages including visual studio and all kinds of other junk.

Take a look at option 3 on this page, have not tried it myself, since I use VS daily http://fsharp.org/use/windows/

Re: Functional Programming Patterns

#40

I am currently taking EdX's Intro to Functional Programming mooc, taught by Erik Meijer (with his crazy shirts), which uses Haskell to teach functional programming concepts. I am wondering if there are any other good resources for teaching the functional programming paradigms. Anybody care to recommend me some resources? Also, I mainly work with Ruby and Javascript in my full time job. Currently, in school, I use Jav…

Read "Functional JavaScript" and "JavaScript Allonge" books from this list http://bahmutov.calepin.co/javascript-books.html

Also, I have been blogging a lot about functional programming in javascript with practical code examples http://bahmutov.calepin.co/tag/functional.html

In particular how to go from imperative style to functional to reactive in JavaScript http://bahmutov.calepin.co/journey-from-procedural-to-reacti...

Post reply on HN