Friends In a few weeks I’m giving a talk to a bunch of genomics folk at the
Sanger Institute about Haskell. They do lots of programming, but they aren’t computer scientists. I can tell them plenty about Haskell, but I’m ill-equipped to answer the main question in their minds:
why should I even care about Haskell? I’m too much of a biased witness. So I thought I’d ask you for help. War stories perhaps – how using Haskell worked (or didn’t) for you. But rather than talk generalities, I’d love to illustrate with copious examples of beautiful
code.
The challenge is, of course, that this audience will know no Haskell, so muttering about Cartesian Closed Categories isn’t going to do it for them. I need examples that I can present in 5
minutes, without needing a long setup. To take a very basic example, consider Quicksort using list comprehensions, compared with its equivalent in C. It’s so short, so obviously right, whereas doing the right thing with in-place
update in C notoriously prone to fencepost errors etc. But it also makes much less good use of memory, and is likely to run slower. I think I can do that in 5 minutes. Another thing that I think comes over easily is the ability to abstract: generalising sum and product to fold by abstracting out a functional argument; generalising at the type level by polymorphism,
including polymorphism over higher-kinded type constructors. Maybe 8 minutes. But you will have more and better ideas, and (crucially) ideas that are more credibly grounded in the day to day reality of writing programs that get work done. Pointers to your favourite blog posts would be another avenue. (I love the Haskell Weekly News.) Finally, I know that some of you use Haskell specifically for genomics work, and maybe some of your insights would be particularly relevant for the Sanger audience. Thank you! Perhaps your responses on this thread (if any) may be helpful to more than just me. Simon _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
If you want a sorting algorithm, go for bottom-up merge sort. That's a *real* merge sort (unlike the non-randomized "QuickSort" you mention), and dead simple. On Wed, Jul 11, 2018, 8:10 AM Simon Peyton Jones via Haskell-Cafe <[hidden email]> wrote:
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Haskell - Haskell-Cafe mailing list
On Wed, Jul 11, 2018 at 12:10:21PM +0000, Simon Peyton Jones via Haskell-Cafe wrote:
> So I thought I'd ask you for help. War stories perhaps - how using > Haskell worked (or didn't) for you. But rather than talk generalities, > I'd love to illustrate with copious examples of beautiful code. > * Can you identify a few lines of Haskell that best characterise > what you think makes Haskell distinctively worth caring about? > Something that gave you an "aha" moment, or that feeling of joy when > you truly make sense of something for the first time. If your most of your audience uses a dynamically typed language, I would introduce type inference and how small, painful bugs can be tracked down by the compiler without having to write a single type signature bar top level. Another good one is implementing a tricky function with holes (in what I have seen described as `hole-driven` development. Unfortunately, one of Haskell strongest suit (ease of refactoring) doesn't really shine in bite-sized examples! _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
Hello, Francesco! For me - phantom types. And may be types families.
Also good is "map" function which replace visitor pattern is short way, but it exists in most modern languages 11.07.2018 15:31, Francesco Ariis wrote: > On Wed, Jul 11, 2018 at 12:10:21PM +0000, Simon Peyton Jones via Haskell-Cafe wrote: >> So I thought I'd ask you for help. War stories perhaps - how using >> Haskell worked (or didn't) for you. But rather than talk generalities, >> I'd love to illustrate with copious examples of beautiful code. >> * Can you identify a few lines of Haskell that best characterise >> what you think makes Haskell distinctively worth caring about? >> Something that gave you an "aha" moment, or that feeling of joy when >> you truly make sense of something for the first time. > If your most of your audience uses a dynamically typed language, > I would introduce type inference and how small, painful bugs can > be tracked down by the compiler without having to write a single > type signature bar top level. > > Another good one is implementing a tricky function with holes > (in what I have seen described as `hole-driven` development. > > Unfortunately, one of Haskell strongest suit (ease of refactoring) > doesn't really shine in bite-sized examples! > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Haskell - Haskell-Cafe mailing list
When teaching, I like to present
Property based testing - because it is so useful in itself, and it shows the power of type-level computation - the compiler constructs the dictionaries, both for testing (class Testable p), and for generating test data (class Serial a), just from the type of the property to be tested. I guess that Java folks could do this via reflection? But the popular benchmark these days is not Java - it's Python? Then it's good because there's no types that would help. Exact choice of framework - (quick|small|lean)check does not matter much for an introductory presentation. I do have a preference for enumeration by size (leancheck) not by depth (smallcheck) or randomly (quick). But then, smallcheck can enumerate functions, which is useful from the beginning (if you want to show properties of higher order functions). But then, proving is better than testing, so you might want to mention "theorems for free"? But again - the JS programmer's reaction will be: obtain a theorem from a type? what's a type? - J.W. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
11.07.2018 15:46, Johannes Waldmann wrote:
> But the popular benchmark these days is not Java - it's Python? > Then it's good because there's no types that would help. Already.. import typing ;) _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Paul
My goodness... For me it was THE "aha" moment, or rather a long period... The problem with popularizing laziness is that too many short comments (on Internet) on it are not serious. People speak mainly about infinite lists (as if somebody really cared about this "infinity"), or that lazy program do not evaluate some expressions, which should *economise* some time, which usually is not true... * For me, lazy programs permit to represent dynamic processes as
data. Iterations as mathematical structures. Co-recursive perturbational schemes (or asymptotic expansions, etc.), which are 10 or more times shorter than the orthodox approaches, and remain readable, and natural. Laziness makes it possible to play with continuations, thus: "making future explicit", in a particularly constructive manner. =========================== Second section... Somebody mentioned "type families". Why not, but for an audience outside of the FP realm?? All the best.
Jerzy Karczmarczuk /Caen, France/ _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
There was a Functional Programming Meetup in CT recently, by people doing genomics[1] Things they emphasized were DSLs, and using parser-combinators and pretty-printers to do so. A lot of the work relates to reading data in from standard genomic databases, and being able to represent what comes out. Alan On 11 July 2018 at 15:07, Jerzy Karczmarczuk <[hidden email]> wrote:
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Haskell - Haskell-Cafe mailing list
Not sure if this helps, but the following two code snippets (taken from Rosetta code) for computing the generalized Cartesian product of a list of lists might exemplify a very important aspect of Haskell: Haskell programmers must invest a lot of time into learning functional programming, but once they speak this common language, the code tends to be easier to understand, maintain, and reason about. The Java solution requires to think about all sort of lower level details on how to iterate the lists and construct the result. It even mixes iterations with more "functional" idioms: import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Optional.of;
import static java.util.stream.Collectors.toList;
import java.util.List;
public class CartesianProduct {
public List<?> product(List<?>... a) {
if (a.length >= 2) {
List<?> product = a[0];
for (int i = 1; i < a.length; i++) {
product = product(product, a[i]);
}
return product;
}
return emptyList();
}
private <A, B> List<?> product(List<A> a, List<B> b) {
return of(a.stream()
.map(e1 -> of(b.stream().map(e2 -> asList(e1, e2)).collect(toList())).orElse(emptyList()))
.flatMap(List::stream)
.collect(toList())).orElse(emptyList());
}
} A programmer that spent a lot of time studying Monads and playing around with them, and that understands the Monad instances for lists, might come up with the following solution in Haskell: cartProdN :: [[a]] -> [[a]]
cartProdN = sequence This also made me realize of two things: 0. Haskell will never be mainstream, because there are not a lot of programmers out there who are willing to do the investment required for learning the necessary concepts to understand and write code like the one shown above. 1. Haskell has rendered me unemployable for almost all jobs that do not involve Haskell codebases. Imagine having to maintain code like the first snippet, replicated in a 10K LOC codebase. And yes, I did use the code above in production :) On Wed, Jul 11, 2018 at 2:10 PM Simon Peyton Jones via Haskell-Cafe <[hidden email]> wrote:
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Haskell - Haskell-Cafe mailing list
I have several short examples that I quite like:
#2: enumerate all strings on an alphabet (this uses laziness!)
#4: Return all subsets of a list
I also have two blog posts I wrote that contain lots of short examples. The first contains lots of short-but-interesting programs and the second contains examples of how expressive Haskell is (by doing the same thing multiple times): http://blog.vmchale.com/article/haskell-aphorisms http://blog.vmchale.com/article/sum On 07/11/2018 07:10 AM, Simon Peyton Jones via Haskell-Cafe wrote:
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
I'm more on the beginner side, but reading up on the difference between print and putStrLn, and pure and return. Also, understanding the Maybe Monad. Finally, reading through some probability randomness examples of rolling dice (for the chapter on State Monad) and seeing how mathematical they look (ie they are similar to how I would reason about them just knowing statistics). Oh yeah..and folds. Fold all the things. - Krystal On 11 July 2018 at 06:46, Vanessa McHale <[hidden email]> wrote:
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Vanessa McHale
Vanessa, I added your blog to my bookmarks :) Thanks 11.07.2018 16:46, Vanessa McHale wrote:
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Damian Nadales
On 07/11/2018 09:36 AM, Damian Nadales
wrote:
Replace "Haskell" with "Java" in the previous sentence, and you would have an equally truthful statement. :) I spent years getting comfortable with OO languages, and then I spent years getting familiar with Haskell. For someone who only knows Haskell (and I know such a person), I couldn't imagine teaching them Java well enough to write that code! Semicolons... Brackets *and* whitespace delineation (which is required, and which is customary?) ... import "static" ... "public", "class", "private" ... eager evaluation ... pass-by-reference/whatever ... procedural statements ... these things are all mind-boggling if you don't learn them early. In short, I don't think the investment required in Haskell is different than any other programming language. As with natural languages, there are no absolute difficulties, only relative ones. (This might actually be a useful point to bring up when speaking to non-Haskellers, so perhaps this message isn't as off-topic as I initially assumed.) _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Haskell - Haskell-Cafe mailing list
> In a few weeks I'm giving a talk to a bunch of genomics folk at the Sanger
> Institute<https://www.sanger.ac.uk/> about Haskell. They do lots of > programming, but they aren't computer scientists. > I can tell them plenty about Haskell, but I'm ill-equipped to answer the > main question in their minds: why should I even care about Haskell? I'm too > much of a biased witness. I don't much like the monad solution for side-effects, but if those guys might have some knowledge of the horror of concurrent programming with locks, the STM system would be a good candidate. Stefan _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
I find it quite elegant! The fact that you can define the IO
monad in Haskell was quite a revelation. And it's especially nice
when paired with a demonstration of C FFI (where you might *need*
to sequence side effects such as freeing a value after it has been
read). newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) On 07/11/2018 09:14 AM, Stefan Monnier
wrote:
In a few weeks I'm giving a talk to a bunch of genomics folk at the Sanger Institute<https://www.sanger.ac.uk/> about Haskell. They do lots of programming, but they aren't computer scientists. I can tell them plenty about Haskell, but I'm ill-equipped to answer the main question in their minds: why should I even care about Haskell? I'm too much of a biased witness.I don't much like the monad solution for side-effects, but if those guys might have some knowledge of the horror of concurrent programming with locks, the STM system would be a good candidate. Stefan _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. --
Vanessa McHale Functional Compiler Engineer | Chicago, IL Website: www.iohk.io Twitter: @vamchale PGP Key ID: 4209B7B5 ![]() ![]() ![]() ![]() This e-mail and any file transmitted with it are confidential and intended solely for the use of the recipient(s) to whom it is addressed. Dissemination, distribution, and/or copying of the transmission by anyone other than the intended recipient(s) is prohibited. If you have received this transmission in error please notify IOHK immediately and delete it from your system. E-mail transmissions cannot be guaranteed to be secure or error free. We do not accept liability for any loss, damage, or error arising from this transmission _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Haskell - Haskell-Cafe mailing list
This is not necessarily related to Haskell, as I've had this A-HA moment
while watching the 1984 SIPC lectures from MIT. Anyway, at some point, Mr Sussman (or was it Mr Abelson?) used `+` as an argument to another function. I was bedazzled! First of all, it was the syntactic novelty — `+` was not some rigid part of the syntax, it was just a name — secondly, it was not any name, it was the name of a *function* that was sent to another function. It was probably my first encounter with higher-order functions. If I remember correctly, the code was along the lines of: foldl (+) 0 [1,2,3] On 11/07/2018 15:10, Simon Peyton Jones via Haskell-Cafe wrote: > Friends > > In a few weeks I’m giving a talk to a bunch of genomics folk at the > Sanger Institute <https://www.sanger.ac.uk/> about Haskell. They do > lots of programming, but they aren’t computer scientists. > > I can tell them plenty about Haskell, but I’m ill-equipped to answer the > main question in their minds: /why should I even care about Haskell/? > I’m too much of a biased witness. > > So I thought I’d ask you for help. War stories perhaps – how using > Haskell worked (or didn’t) for you. But rather than talk generalities, > I’d love to illustrate with copious examples of beautiful code. > > * Can you identify a few lines of Haskell that best characterise what > you think makes Haskell distinctively worth caring about? > Something that gave you an “aha” moment, or that feeling of joy when > you truly make sense of something for the first time. > > The challenge is, of course, that this audience will know no Haskell, so > muttering about Cartesian Closed Categories isn’t going to do it for > them. I need examples that I can present in 5 minutes, without needing > a long setup. > > To take a very basic example, consider Quicksort using list > comprehensions, compared with its equivalent in C. It’s so short, so > obviously right, whereas doing the right thing with in-place update in C > notoriously prone to fencepost errors etc. But it also makes much less > good use of memory, and is likely to run slower. I think I can do that > in 5 minutes. > > Another thing that I think comes over easily is the ability to abstract: > generalising sum and product to fold by abstracting out a functional > argument; generalising at the type level by polymorphism, including > polymorphism over higher-kinded type constructors. Maybe 8 minutes. > > But you will have more and better ideas, and (crucially) ideas that are > more credibly grounded in the day to day reality of writing programs > that get work done. > > Pointers to your favourite blog posts would be another avenue. (I love > the Haskell Weekly News.) > > Finally, I know that some of you use Haskell specifically for genomics > work, and maybe some of your insights would be particularly relevant for > the Sanger audience. > > Thank you! Perhaps your responses on this thread (if any) may be > helpful to more than just me. > > Simon > > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- Ionuț G. Stan | http://igstan.ro | http://bucharestfp.ro _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
For me there were two important "aha" moments. Right at the
beginning I was drawn in by using ADTs and pattern-matching on them.
It's so simple and plain and now it's the first thing I miss in any
other language I have to work with. I feel like this would make a short, compelling example for programmers coming from any other background. The second
was reading Wadler's "Monads for Functional Progamming" (and reading it a
second and third time, if we're being honest). The ways in which he
takes three seemingly disconnected examples and reduces them to this
broader mathematical abstraction: I found it quite beautiful and
surprising once I fully appreciated it. On Wed, Jul 11, 2018 at 7:29 AM Ionuț G. Stan <[hidden email]> wrote: This is not necessarily related to Haskell, as I've had this A-HA moment -- Erik Aker _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by Bryan Richter-2
I speak only from my own narrow perspective. I'd say programming is hard, but functional programming is harder. Maybe that's why Java replaced Haskell in some universities curricula https://chrisdone.com/posts/dijkstra-haskell-java. For some reason most programmers I know are not scared of learning OO, but they fear functional programming. I think the reason might be that OO concepts like inheritance and passing messages between objects are a bit more concrete and easier to grasp (when you present toy examples at least). Then you have design patterns, which have intuitive names and give some very general guidelines that one can try after reading them (and add his/her own personal twist). I doubt people can read the Monad laws and make any sense out of them at the first try. Maybe FP and OO are perceived as equally hard, but that was not my impression so far.
Well, I guess that's subjective (as our two opinions illustrate ;)). It'd be nice to have some empirical evidence of this, but I couldn't find any paper on the subject ...
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by erik
I think using laziness for dynamic programming is a pretty amazing thing: http://jelv.is/blog/Lazy-Dynamic-Programming/ On Wed, Jul 11, 2018 at 10:37 AM erik <[hidden email]> wrote:
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
In reply to this post by erik
> For me there were two important "aha" moments. Right at the beginning I was
> drawn in by using ADTs and pattern-matching on them. It's so simple and > plain and now it's the first thing I miss in any other language I have to > work with. I feel like this would make a short, compelling example for > programmers coming from any other background. Indeed, the one thing I really miss when hacking on Elisp is the great help I get from my Haskell/ML typecheckers when I modify one of my datatypes, showing me exhaustively (or close enough) all the places where changes are needed. Stefan _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. |
Free forum by Nabble | Edit this page |