What is your favourite Haskell "aha" moment?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
114 messages Options
123456
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Conal Elliott
In this conversation I didn't mean that IO is not a monad (a separate topic), but rather that the "definition" of IO is incompatible with the truth of IO. (It's perhaps akin to "the Ken Thompson hack"; see http://wiki.c2.com/?TheKenThompsonHack.)

As for IO being a monad, I think the claim is not only not true but is ill-defined and hence "not even false". For a well-defined claim/question, one would need an agreed-upon notion of equality, since the Monad laws are equalities.

(Of course there are *other* input-output-like types, perhaps subsets of Haskell IO, for which we can define equality usefully, even based on a denotation. But those types are not IO. Some related remarks at http://conal.net/blog/posts/notions-of-purity-in-haskell#comment-442.)

-- Conal


On Wed, Jul 11, 2018 at 6:59 PM, Vanessa McHale <[hidden email]> wrote:

I'm not sure I follow. Do you mean that IO is not a monad because equivalence of values cannot be defined? Or is it something deeper?

On 07/11/2018 05:19 PM, Conal Elliott wrote:
The fact that you can define the IO monad in Haskell was quite a revelation.

But it's *not* a fact. It's a lie. And one of the most devious sort, since the source code appears to agree. The purported definition couldn't possibly explain concurrency.

On Wed, Jul 11, 2018 at 7:21 AM, Vanessa McHale <[hidden email]> wrote:

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

Input Output

Twitter Github LinkedIn


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.



_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Joachim Durchholz
In reply to this post by Haskell - Haskell-Cafe mailing list
Am 11.07.2018 um 14:10 schrieb Simon Peyton Jones via Haskell-Cafe:
> 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;

You can expound more on that: People don't have to write loops anymore
(with their fencepost issues etc.). It's like a "for" loop, but written
using in-language facilities instead of having to live with what the
language designer does.

This means you can roll your own loop constructs.

Consider iterating over the elements of a data structure such as List,
Tree, etc. Most languages offer an Iterable interface, which tends to be
somewhat messy to implement.
With a higher-order function, you can just write down the loop, *once*,
and the loop body will be provided by a function parameter, and voilà!
you have your loop construct.

HTH
Jo
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Joachim Durchholz
In reply to this post by Damian Nadales
Am 11.07.2018 um 15:36 schrieb Damian Nadales:
> 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.

For an uninitiated, learning Java takes about the same amount of time as
learning Haskell. Learning monads is like learning Spring or one of the
gazillion other library frameworks out there in the Java world, so even
that isn't much of a difference.

If you're a programmer already, then changes are that Haskell is indeed
harder to learn than most other languages you might want to learn,
because the overlap of standard concepts and techniques is smaller.

IOW it's harder to teach Haskell to programmers than to nonprogrammers.
Which also means that our conclusions from our experience as programmers
do not predict much about Haskell's future.

> 1. Haskell has rendered me unemployable for almost all jobs that do not
> involve Haskell codebases.

This can be avoided if you find a job that has a 50-50 split of Haskell
and non-Haskell work, but that's not always possible and I agree this
can become a huge problem.

Regards,
Jo
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: Investing in languages (Was: What is your favourite Haskell "aha" moment?)

Joachim Durchholz
In reply to this post by Damian Nadales
Am 11.07.2018 um 16:36 schrieb Damian Nadales:
>
> I speak only from my own narrow perspective. I'd say programming is
> hard, but functional programming is harder.

Actually it's pretty much the opposite, I hear from teachers.

> Maybe that's why Java replaced Haskell in some universities
> curricula
The considerations are marketable skills.
A considerable fraction of students is looking at the curriculum and at
job offers, and if they find that the lists don't match, they will go to
another university.
Also, industry keeps lobbying for teaching skills that they can use.
Industry can give money to universities so this gives them influence on
the curriculum (and only if they get time to talk the topic over with
the dean). This aspect can vary considerably between countries,
depending on how much money the universities tend to acquire from industry.

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

Programmers were *very* scared of OO in the nineties. It took roughly a
decade or two (depending on where you put the starting point) to get
comfortable with OO.

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

OO is about how to deal with having to pack everything into its own
class (and how to arrange stuff into classes).
Functional is about how to deal with the inability to update. Here, the
functional camp actually has the easier job, because you can just tell
people to just write code that creates new data objects and get over
with it. Performance concerns can be handwaved away by saying that the
compiler is hyper-aggressive, and "you can look at the intermediate code
if you suspect the compiler is the issue". (Functional is a bit similar
to SQL here, but the SQL optimizers are much less competent than GHC at
detecting optimization opportunities.)

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

That's true, but much of the misconceptions around monads from the first
days have been cleared up.
But yes the monad laws are too hard to read. OTOH you won't be able to
read the Tree code in the JDK without the explanations either.
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: Investing in languages (Was: What is your favourite Haskell "aha" moment?)

Tony Morris-4
 I used to teach undergrad OOP nonsense. I have been teaching FP for 15
years. [^1]

The latter is *way* easier. Existing programmers are more difficult than
children, but still way easier to teach FP than all the other stuff.

[^1]: Canberra anyone? https://qfpl.io/posts/2018-canberra-intro-to-fp/


On 07/12/2018 04:23 PM, Joachim Durchholz wrote:

> Am 11.07.2018 um 16:36 schrieb Damian Nadales:
>>
>> I speak only from my own narrow perspective. I'd say programming is
>> hard, but functional programming is harder.
>
> Actually it's pretty much the opposite, I hear from teachers.
>
>> Maybe that's why Java replaced Haskell in some universities
>> curricula
> The considerations are marketable skills.
> A considerable fraction of students is looking at the curriculum and
> at job offers, and if they find that the lists don't match, they will
> go to another university.
> Also, industry keeps lobbying for teaching skills that they can use.
> Industry can give money to universities so this gives them influence
> on the curriculum (and only if they get time to talk the topic over
> with the dean). This aspect can vary considerably between countries,
> depending on how much money the universities tend to acquire from
> industry.
>
>> 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.
>
> Programmers were *very* scared of OO in the nineties. It took roughly
> a decade or two (depending on where you put the starting point) to get
> comfortable with OO.
>
> >
>   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).
>
> OO is about how to deal with having to pack everything into its own
> class (and how to arrange stuff into classes).
> Functional is about how to deal with the inability to update. Here,
> the functional camp actually has the easier job, because you can just
> tell people to just write code that creates new data objects and get
> over with it. Performance concerns can be handwaved away by saying
> that the compiler is hyper-aggressive, and "you can look at the
> intermediate code if you suspect the compiler is the issue".
> (Functional is a bit similar to SQL here, but the SQL optimizers are
> much less competent than GHC at detecting optimization opportunities.)
>
>> 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.
>
> That's true, but much of the misconceptions around monads from the
> first days have been cleared up.
> But yes the monad laws are too hard to read. OTOH you won't be able to
> read the Tree code in the JDK without the explanations either.
> _______________________________________________
> 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.

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Investing in languages (Was: What is your favourite Haskell "aha" moment?)

Brett Gilio
Tony,

I am curious on your attitude towards multi-paradigm and ML-like
languages. I agree that functional programming is easily the better of
the bundle in many forms of application logic and elegance (which is why
I have come to love Scheme and Haskell), but do you see any room for
those languages like F# or Rust which have large capacities for FP but
are either functional-first (but not pure) or a hybrid?

Brett Gilio

On 07/12/2018 01:35 AM, Tony Morris wrote:

>   I used to teach undergrad OOP nonsense. I have been teaching FP for 15
> years. [^1]
>
> The latter is *way* easier. Existing programmers are more difficult than
> children, but still way easier to teach FP than all the other stuff.
>
> [^1]: Canberra anyone? https://qfpl.io/posts/2018-canberra-intro-to-fp/
>
>
> On 07/12/2018 04:23 PM, Joachim Durchholz wrote:
>> Am 11.07.2018 um 16:36 schrieb Damian Nadales:
>>>
>>> I speak only from my own narrow perspective. I'd say programming is
>>> hard, but functional programming is harder.
>>
>> Actually it's pretty much the opposite, I hear from teachers.
>>
>>> Maybe that's why Java replaced Haskell in some universities
>>> curricula
>> The considerations are marketable skills.
>> A considerable fraction of students is looking at the curriculum and
>> at job offers, and if they find that the lists don't match, they will
>> go to another university.
>> Also, industry keeps lobbying for teaching skills that they can use.
>> Industry can give money to universities so this gives them influence
>> on the curriculum (and only if they get time to talk the topic over
>> with the dean). This aspect can vary considerably between countries,
>> depending on how much money the universities tend to acquire from
>> industry.
>>
>>> 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.
>>
>> Programmers were *very* scared of OO in the nineties. It took roughly
>> a decade or two (depending on where you put the starting point) to get
>> comfortable with OO.
>>
>>>
>>    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).
>>
>> OO is about how to deal with having to pack everything into its own
>> class (and how to arrange stuff into classes).
>> Functional is about how to deal with the inability to update. Here,
>> the functional camp actually has the easier job, because you can just
>> tell people to just write code that creates new data objects and get
>> over with it. Performance concerns can be handwaved away by saying
>> that the compiler is hyper-aggressive, and "you can look at the
>> intermediate code if you suspect the compiler is the issue".
>> (Functional is a bit similar to SQL here, but the SQL optimizers are
>> much less competent than GHC at detecting optimization opportunities.)
>>
>>> 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.
>>
>> That's true, but much of the misconceptions around monads from the
>> first days have been cleared up.
>> But yes the monad laws are too hard to read. OTOH you won't be able to
>> read the Tree code in the JDK without the explanations either.
>> _______________________________________________
>> 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.
>
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Monad laws (Was: Investing in languages (Was: What is your favourite Haskell "aha" moment?))

Tom Ellis-5
In reply to this post by Joachim Durchholz
> the monad laws are too hard to read.

FWIW the monad laws are not hard to *read* if written in this form

    return >=> f = f
    f >=> return = f
    (f >=> g) >=> h = f >=> (g >=> h)

(Whether they're easy to *understand* in that form is another matter.)
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Joachim Durchholz
In reply to this post by Haskell - Haskell-Cafe mailing list
Am 11.07.2018 um 18:24 schrieb Simon Peyton Jones via Haskell-Cafe:

> One thing that stands our for me is the ability to abstract over type
> *constructors*:
>
>              f :: forall (m :: * -> *) (a :: *). Monad m => a -> m a
>
> That ability is what has given rise to a stunningly huge collection of
> abstractions: not just Monad, but Functor, Applicative, Traversable,
> Foldable, etc etc etc.   Really a lot.  It opens up a new way to think
> about the world.  But only made possible by that one feature.   (Plus
> type classes of course.)
>
> Do any statically typed languages other than Haskell and Scala do this?

Not this, but this description reminded me of my own A-Ha moment when I
looked at Eiffel's data structure library.
Eiffel does multiple inheritance pretty well, so they went ahead and
structured the library using a classifier approach: bounded vs.
unbounded data structures, updatable vs. non-updatable ones, indexable
vs. merely iterable. Any concrete class is a subtype of any of these,
and of course the classifying types had subtypes that defined more
detail, e.g. set vs. multiset (bag) vs. map.

This created an extraordinarily uniform API where equal things had equal
names and consistent semantics, something that rare even for
well-designed libraries.
(The library does have its weaknesses, which are due to the designer's
aggressively update-in-place mindset, so in a discussion it's probably
best to avoid mentioning Eiffel if you wish to highlight FP.)
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: Monad laws (Was: Investing in languages (Was: What is your favourite Haskell "aha" moment?))

Alexis King
In reply to this post by Tom Ellis-5
> On Jul 12, 2018, at 01:42, Tom Ellis <[hidden email]> wrote:
>
>> the monad laws are too hard to read.
>
> FWIW the monad laws are not hard to *read* if written in this form
>
>    return >=> f = f
>    f >=> return = f
>    (f >=> g) >=> h = f >=> (g >=> h)
>
> (Whether they're easy to *understand* in that form is another matter.)

Here is another formulation of the monad laws that is less frequently discussed than either of the ones using bind or Kleisli composition:

    (1) join . return = id
    (2) join . fmap return = id
    (3) join . join = join . map join

These laws map less obviously to the common ones, but I think they are easier to understand (not least because `join` is closer to the “essence” of what a monad is than >>=). (1) and (2) describe the intuitive notion that adding a layer and squashing it should be the identity function, whether you add the new layer on the outside or on the inside. Likewise, (3) states that if you have three layers and squash them all together, it doesn’t matter whether you squash the inner two or outer two together first.

(Credit goes to HTNW on Stack Overflow for explaining this to me. https://stackoverflow.com/a/45829556/465378)

_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Graham Klyne-2
In reply to this post by Haskell - Haskell-Cafe mailing list
Although I don't program regularly in Haskell these days (my poison is Python,
mainly for Web framework support), I do occasionally find myself coding tricky
manipulations in Haskell first as I find it easier to concentrate on the
essentials of an algorithm.  Once I have the Haskell code written and tested, I
generally find it fairly easy to map the algorithm into Python (using higher
order functions as appropriate).

Here are some examples:

https://github.com/gklyne/annalist/blob/master/spike/rearrange-list/move_up.lhs
https://github.com/gklyne/annalist/blob/master/spike/tree-scan/tree_scan.lhs

And the corresponding code in the actual application:

https://github.com/gklyne/annalist/blob/4d21250a3457c72d4f6525e5a4fac40d4c0ca1c8/src/annalist_root/annalist/views/entityedit.py#L2489

https://github.com/gklyne/annalist/blob/master/src/annalist_root/annalist/models/entity.py#L245

#g
--


On 11/07/2018 13: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.
>
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Brett Gilio
Python is poison, indeed. ;)

Brett Gilio
[hidden email] | [hidden email]
Free Software -- Free Society!

On 07/12/2018 04:56 AM, Graham Klyne wrote:

> Although I don't program regularly in Haskell these days (my poison is
> Python, mainly for Web framework support), I do occasionally find myself
> coding tricky manipulations in Haskell first as I find it easier to
> concentrate on the essentials of an algorithm.  Once I have the Haskell
> code written and tested, I generally find it fairly easy to map the
> algorithm into Python (using higher order functions as appropriate).
>
> Here are some examples:
>
> https://github.com/gklyne/annalist/blob/master/spike/rearrange-list/move_up.lhs 
>
> https://github.com/gklyne/annalist/blob/master/spike/tree-scan/tree_scan.lhs 
>
>
> And the corresponding code in the actual application:
>
> https://github.com/gklyne/annalist/blob/4d21250a3457c72d4f6525e5a4fac40d4c0ca1c8/src/annalist_root/annalist/views/entityedit.py#L2489 
>
>
> https://github.com/gklyne/annalist/blob/master/src/annalist_root/annalist/models/entity.py#L245 
>
>
> #g
> --
>
>
> On 11/07/2018 13: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.
>>
> _______________________________________________
> 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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Graham Klyne-2
In reply to this post by Haskell - Haskell-Cafe mailing list
Another example of Haskell-influenced programming in another language (this time
Jacascript, before promises and event driven frameworks were a thing) - I
implemented a class somewhat based on Hasell's Monad class to organize callback
sequencing in an jQuery-based UI.  The (aged) code is here:

https://github.com/gklyne/shuffl/blob/master/src/AsyncComputation.js

and an example of use:

https://github.com/gklyne/shuffl/blob/master/src/shuffl-loadworkspace.js#L186

#g
--


On 11/07/2018 13: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.
>
_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: Investing in languages (Was: What is your favourite Haskell "aha" moment?)

Vanessa McHale
In reply to this post by Brett Gilio
I wouldn't say Rust has a large capacity for FP. I am not familiar with
F#. The thing that makes FP infeasible in Rust is not the lack of purity
but rather the fact that affine types make it difficult to treat
functions as first-class values.


On 07/12/2018 01:40 AM, Brett Gilio wrote:

> Tony,
>
> I am curious on your attitude towards multi-paradigm and ML-like
> languages. I agree that functional programming is easily the better of
> the bundle in many forms of application logic and elegance (which is
> why I have come to love Scheme and Haskell), but do you see any room
> for those languages like F# or Rust which have large capacities for FP
> but are either functional-first (but not pure) or a hybrid?
>
> Brett Gilio
>
> On 07/12/2018 01:35 AM, Tony Morris wrote:
>>   I used to teach undergrad OOP nonsense. I have been teaching FP for 15
>> years. [^1]
>>
>> The latter is *way* easier. Existing programmers are more difficult than
>> children, but still way easier to teach FP than all the other stuff.
>>
>> [^1]: Canberra anyone? https://qfpl.io/posts/2018-canberra-intro-to-fp/
>>
>>
>> On 07/12/2018 04:23 PM, Joachim Durchholz wrote:
>>> Am 11.07.2018 um 16:36 schrieb Damian Nadales:
>>>>
>>>> I speak only from my own narrow perspective. I'd say programming is
>>>> hard, but functional programming is harder.
>>>
>>> Actually it's pretty much the opposite, I hear from teachers.
>>>
>>>> Maybe that's why Java replaced Haskell in some universities
>>>> curricula
>>> The considerations are marketable skills.
>>> A considerable fraction of students is looking at the curriculum and
>>> at job offers, and if they find that the lists don't match, they will
>>> go to another university.
>>> Also, industry keeps lobbying for teaching skills that they can use.
>>> Industry can give money to universities so this gives them influence
>>> on the curriculum (and only if they get time to talk the topic over
>>> with the dean). This aspect can vary considerably between countries,
>>> depending on how much money the universities tend to acquire from
>>> industry.
>>>
>>>> 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.
>>>
>>> Programmers were *very* scared of OO in the nineties. It took roughly
>>> a decade or two (depending on where you put the starting point) to get
>>> comfortable with OO.
>>>
>>>>
>>>    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).
>>>
>>> OO is about how to deal with having to pack everything into its own
>>> class (and how to arrange stuff into classes).
>>> Functional is about how to deal with the inability to update. Here,
>>> the functional camp actually has the easier job, because you can just
>>> tell people to just write code that creates new data objects and get
>>> over with it. Performance concerns can be handwaved away by saying
>>> that the compiler is hyper-aggressive, and "you can look at the
>>> intermediate code if you suspect the compiler is the issue".
>>> (Functional is a bit similar to SQL here, but the SQL optimizers are
>>> much less competent than GHC at detecting optimization opportunities.)
>>>
>>>> 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.
>>>
>>> That's true, but much of the misconceptions around monads from the
>>> first days have been cleared up.
>>> But yes the monad laws are too hard to read. OTOH you won't be able to
>>> read the Tree code in the JDK without the explanations either.
>>> _______________________________________________
>>> 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.
>>
> _______________________________________________
> 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.

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Investing in languages (Was: What is your favourite Haskell "aha" moment?)

Paul

I am afraid that it can lead to flame again, but F# has super-capacity: you can check measuring units, type providers, computation expressions, active patterns, static/dynamic types constraints, constraints on existing method, etc... It's clean, borrows some ideas from Haskell, some are original and Haskell borrows them (but with worse implementation). IMHO for children teaching to FP F# is the best. Even more, currently C# also has a lot of FP features (https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md#arithmetic-simplification  -- is not it super easy and beauty?). Rust is more low level: you should think about memory "management", OOP has some problems... And serious argument for children teaching: salary trends (joke sure) :-) But you can compare salary in F# and Haskell, for example - people often choice language after check current salaries in the market. Also F# is more focused on realistic tasks and business value. It lacks performance, UWP yet (but in progress)... To feel how F# is sexy compare Web application written in Websharper and in any Haskell framework. Haskell is beauty but I'm afraid its fate unfortunately will be the same as one of Common Lisp, NetBSD, etc - it's ground for ideas and experiments and has disputable design. Also it's more-more difficult to teach children to Haskell than to F#...

IMHO is general to teach FP is more easy than to teach OOP if FP is not Haskell (some language which targets more eager/efficient/dynamic/real goals instead of abstract types playing).

12.07.2018 13:28, Vanessa McHale wrote:
I wouldn't say Rust has a large capacity for FP. I am not familiar with
F#. The thing that makes FP infeasible in Rust is not the lack of purity
but rather the fact that affine types make it difficult to treat
functions as first-class values.


On 07/12/2018 01:40 AM, Brett Gilio wrote:
Tony,

I am curious on your attitude towards multi-paradigm and ML-like
languages. I agree that functional programming is easily the better of
the bundle in many forms of application logic and elegance (which is
why I have come to love Scheme and Haskell), but do you see any room
for those languages like F# or Rust which have large capacities for FP
but are either functional-first (but not pure) or a hybrid?

Brett Gilio

On 07/12/2018 01:35 AM, Tony Morris wrote:
  I used to teach undergrad OOP nonsense. I have been teaching FP for 15
years. [^1]

The latter is *way* easier. Existing programmers are more difficult than
children, but still way easier to teach FP than all the other stuff.

[^1]: Canberra anyone? https://qfpl.io/posts/2018-canberra-intro-to-fp/


On 07/12/2018 04:23 PM, Joachim Durchholz wrote:
Am 11.07.2018 um 16:36 schrieb Damian Nadales:
I speak only from my own narrow perspective. I'd say programming is
hard, but functional programming is harder.
Actually it's pretty much the opposite, I hear from teachers.

Maybe that's why Java replaced Haskell in some universities
curricula
The considerations are marketable skills.
A considerable fraction of students is looking at the curriculum and
at job offers, and if they find that the lists don't match, they will
go to another university.
Also, industry keeps lobbying for teaching skills that they can use.
Industry can give money to universities so this gives them influence
on the curriculum (and only if they get time to talk the topic over
with the dean). This aspect can vary considerably between countries,
depending on how much money the universities tend to acquire from
industry.

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.
Programmers were *very* scared of OO in the nineties. It took roughly
a decade or two (depending on where you put the starting point) to get
comfortable with OO.


            
   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).
OO is about how to deal with having to pack everything into its own
class (and how to arrange stuff into classes).
Functional is about how to deal with the inability to update. Here,
the functional camp actually has the easier job, because you can just
tell people to just write code that creates new data objects and get
over with it. Performance concerns can be handwaved away by saying
that the compiler is hyper-aggressive, and "you can look at the
intermediate code if you suspect the compiler is the issue".
(Functional is a bit similar to SQL here, but the SQL optimizers are
much less competent than GHC at detecting optimization opportunities.)

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.
That's true, but much of the misconceptions around monads from the
first days have been cleared up.
But yes the monad laws are too hard to read. OTOH you won't be able to
read the Tree code in the JDK without the explanations either.
_______________________________________________
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.

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


_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

S. Doaitse Swierstra
In reply to this post by Haskell - Haskell-Cafe mailing list
Another thing worth mentioning is the following:

An enormous amount of programmer time is spent on managing memory and scheduling computations. 

1) Automatic garbage collection has freed us from de necessity to think about WHEN THE LIFE OF A VALUE ENDS
2) Lazy evaluation frees of having to think about WHEN THE LIFE OF A VALUE STARTS.

So a lazy purely functional language like Haskell  frees the programmer from having to think about scheduling computations.

Just as you can make garbage collection explicit in your code by using assignments (making explicit that you do not need the value stored in the variable anymore) you can make evaluation in your program explicit by making arguments strict and using `seq` etc. Both these make life more complicated in the first place, although they may lead to faster code taking less memory, but they are optimisations that only should be applied when unavoidable.

Doaitse





Op 11 jul. 2018, om 14:10  heeft Simon Peyton Jones via Haskell-Cafe <[hidden email]> het volgende geschreven:

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. 

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


_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Alexey Raga
In reply to this post by Haskell - Haskell-Cafe mailing list
Not sure if it counts as "aha moments", but when I started with Haskell I had two major reasons (not in any importance order):

1. The ability to define the specification (types) and then "just" follow them in implementation. Sometimes even without having a clear understanding of the things I was using, I felt (and still feel) guided towards the right solution.

2. The ability to refactor fearlessly is a _massive_ productivity boost. Hard to underestimate.

Regards,
Alexey.

On Wed, Jul 11, 2018 at 10:10 PM Simon Peyton Jones via Haskell-Cafe <[hidden email]> wrote:

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.

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

_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Brett Gilio
Alexey, could you expand on what you mean in your first point? I am
quite intrigued. I do not use Haskell often, but that could be something
of interest to me in-and-out of Haskell.

Brett Gilio
[hidden email] | [hidden email]
Free Software -- Free Society!

On 07/12/2018 07:46 AM, Alexey Raga wrote:

> Not sure if it counts as "aha moments", but when I started with Haskell
> I had two major reasons (not in any importance order):
>
> 1. The ability to define the specification (types) and then "just"
> follow them in implementation. Sometimes even without having a clear
> understanding of the things I was using, I felt (and still feel) guided
> towards the right solution.
>
> 2. The ability to refactor fearlessly is a _massive_ productivity boost.
> Hard to underestimate.
>
> Regards,
> Alexey.
>
> On Wed, Jul 11, 2018 at 10:10 PM Simon Peyton Jones via Haskell-Cafe
> <[hidden email] <mailto:[hidden email]>> 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.
>
>
>
> _______________________________________________
> 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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Alexey Raga
In reply to this post by Haskell - Haskell-Cafe mailing list
Some code examples that I usually show/explain to someone who is interested in Haskell but have no previous exposure:

ADTs. Even for something as simple as

data ShoppingCartCommand
  = CreateCart UserId
  | AddToCart CartId ProductId Quantity
  | ClearCart CartId
  deriving (Eq, Show)

This would be many-many lines of non-trivial C# or Java code (you would need to think about abstract classes or interfaces, correctly override toString, equality and getHashCode, write tests for all this, etc). 

If the audience is familiar with C#, then explaining the ability to abstract over type constructors may work well. In C# there is no way to generalise over, say, IEnumerable<T> and IObservable<T>. If you want to accept both then you'd have to write the same LINQ statements twice (or convert one into another, which is not always possible).

Regards,
Alexey.


On Wed, Jul 11, 2018 at 10:10 PM Simon Peyton Jones via Haskell-Cafe <[hidden email]> wrote:

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.

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

_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

S. Doaitse Swierstra
In reply to this post by Brett Gilio

> Op 12 jul. 2018, om 15:01  heeft Brett Gilio <[hidden email]> het volgende geschreven:
>
> Alexey, could you expand on what you mean in your first point? I am quite intrigued. I do not use Haskell often, but that could be something of interest to me in-and-out of Haskell.

In the old days, when I wrote Pascal programs, and I wanted to swap values I wrote code like:

function swap (var x, y: integer); begin x := x+y; y := x - y; x := x - y end;

Only to find out that if I wanted a swap for a different type this does not work. Hence a lot of coding, and hardly re-use and very error prone. How many functions can’t you write that have this type.

So the question is how many functions can you write with the type (a, a) -> (a, a). If you randomly generate functions of this type there is a chance of 25% you get the right one.

But things become even better:

swap (a, b) = (b, a)

Once you ask for the type you get (a, b) -> (b, a), hence the type completely specifies what swap computes, and the function is even more general than the version of the type above.

 Doaitse



>
> Brett Gilio
> [hidden email] | [hidden email]
> Free Software -- Free Society!
>
> On 07/12/2018 07:46 AM, Alexey Raga wrote:
>> Not sure if it counts as "aha moments", but when I started with Haskell I had two major reasons (not in any importance order):
>> 1. The ability to define the specification (types) and then "just" follow them in implementation. Sometimes even without having a clear understanding of the things I was using, I felt (and still feel) guided towards the right solution.
>> 2. The ability to refactor fearlessly is a _massive_ productivity boost. Hard to underestimate.
>> Regards,
>> Alexey.
>> On Wed, Jul 11, 2018 at 10:10 PM Simon Peyton Jones via Haskell-Cafe <[hidden email] <mailto:[hidden email]>> 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.
>> _______________________________________________
>> 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.

_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: What is your favourite Haskell "aha" moment?

Alexey Raga
In reply to this post by Brett Gilio
> Alexey, could you expand on what you mean in your first point?

I guess that I meant two things here.

First is that when I wrote a signature for my function, the compiler will make its best to help me implement it. It will yell at me, it will not let me use things that I am not supposed to use (according to constraints), etc. 
More precise I am with my types (e.g. use non-empty list instead of just list, use specific ADT instead of Bools, use Age/Weight/Size instead of Int, etc.) - more help I get.

Another thing is that sometimes I'd just play "Type Tetris" to make things compile and work. Try something, the compiler says "No, can't have this", perhaps make a suggestion, try another thing, "aha, next step", etc. Learned so much from these "games" :)

Regards, 
Alexey.

On Thu, Jul 12, 2018 at 11:04 PM Brett Gilio <[hidden email]> wrote:
Alexey, could you expand on what you mean in your first point? I am
quite intrigued. I do not use Haskell often, but that could be something
of interest to me in-and-out of Haskell.

Brett Gilio
[hidden email] | [hidden email]
Free Software -- Free Society!

On 07/12/2018 07:46 AM, Alexey Raga wrote:
> Not sure if it counts as "aha moments", but when I started with Haskell
> I had two major reasons (not in any importance order):
>
> 1. The ability to define the specification (types) and then "just"
> follow them in implementation. Sometimes even without having a clear
> understanding of the things I was using, I felt (and still feel) guided
> towards the right solution.
>
> 2. The ability to refactor fearlessly is a _massive_ productivity boost.
> Hard to underestimate.
>
> Regards,
> Alexey.
>
> On Wed, Jul 11, 2018 at 10:10 PM Simon Peyton Jones via Haskell-Cafe
> <[hidden email] <mailto:[hidden email]>> 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.
>
>
>
> _______________________________________________
> 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.

_______________________________________________
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.
123456