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

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

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

Vilem-Benjamin Liepelt-2
Dear Simon,

I was always impressed by Haskell, but my "aha" moment was when I realised how great it is as a scripting language. How cool is the fact that you can glue together a bunch of small programs and make a bigger program out of it without toil? Haskell helps you get mundane tasks done while being a pleasure to write (in relative terms)!

There are much better examples online—I love Gabriel Gonzalez' turtle library—but I find the following compelling enough, and anybody can understand more or less what is going on with some explanation:



#!/usr/bin/env stack
-- stack script --resolver lts-10.1 --install-ghc

{-# LANGUAGE TypeApplications #-}

import Data.Maybe (mapMaybe)
import Text.Read (readMaybe)

main :: IO ()
main =
  interact
  ( show @Double
  . sum
  . mapMaybe readMaybe
  . words
  )

-- Adapted from a script by Taylor Fausak: https://gist.github.com/tfausak/fcd11dfcec616622033dfb64eb2378e1



Good luck with the presentation!

Best,

Vilem

_______________________________________________
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
On 07/13/2018 02:14 PM, Vilem-Benjamin Liepelt wrote> I was always
impressed by Haskell, but my "aha" moment was when I > realised how
great it is as a *scripting language.*

Absolutely, this. Have you ever tried Xmonad, Vilem? It is such a great
environment for using Haskell in a multitude of capacities, even as a
scripting language.


--
Brett Gilio
[hidden email] | [hidden email]
https://www.parabola.nu/ | https://www.emacs.org/
Free Software -- Free Society!
_______________________________________________
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?

MarLinn
In reply to this post by Vilem-Benjamin Liepelt-2
Warning: I'll be overly harsh in this mail because I assume some people that are new to Haskell might browse this thread now and in the future. I don't mean my comments to be considered personal. On the contrary, I think some of us can learn for their own teaching endeavours.

#!/usr/bin/env stack
-- stack script --resolver lts-10.1 --install-ghc

Imagine a "newbie" running this script just to see what it does. After 15 minutes they'll be disappointed why your small demo took so long to build. Only then do they realize that, what is it today, about half a gigabyte maybe, of their monthly "high speed" bandwidth and of their precious space on the cheap but decade-old hard drive is gone.

Of course you need all that data because there's a ghc in that data, but it should say so on the tin. So please never send a script with this line to a "newbie" without big warnings so they can make an informed decision. Maybe they would want to install ghc at their uni to save on that precious bandwidth at home or something similar.

In fact don't even send scripts with this line to seasoned haskellers. If your code is compatible with the ghc 8.2.1 on my system, why should your script assume I want stack to install 8.2.2 right now?

Of course this behaviour is ingrained in the DNA of stack – after all it values convenience for the professional user more than convenience for the unprivileged newcomer – but AFAIU it can be persuaded to be more inclusive. So especially here, we should maybe try to do that.

  interact
  ( show @Double
  . sum
  . mapMaybe readMaybe
  . words
  )

Also, while I do like the scripting possibilities, interact is possibly the worst way to introduce a newcomer to it because you can't really test it in ghci. Apart from all the other shortcomings it has. It is nice in that it hides IO, but…

Again, not meant as an attack, but since we're talking about giving newcomers a good experience, I thought these two points important.

Cheers,
MarLinn


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

Vilem-Benjamin Liepelt-2
In reply to this post by Vilem-Benjamin Liepelt-2
Dear MarLinn,

> Of course you need all that data because there's a ghc in that data, but
> it should say so on the tin. So please never send a script with this
> line to a "newbie" without big warnings so they can make an informed
> decision.

That is a very good point. I just happen to use some particular LTS because I have it cached, so it works instantly for all my scripts. Thank you for reminding me that I shouldn't carelessly just pass this on for others to use without mentioning the caveats you pointed to.

> Also, while I do like the scripting possibilities, interact is possibly
> the worst way to introduce a newcomer to it because you can't really
> test it in ghci.


Your concern about testability in GHCi is valid but minor; you can just make the string transformation function a top-level declaration like so:

```
main = interact sumCLI

sumCLI :: String -> String
sumCLI = show @Double . sum . mapMaybe readMaybe . words
```

IMO `interact` is the easiest way for newcomers to write a script that they can actually use, hence why I opted for this instead of `print . sumCLi =<< getContents`.

Lastly, SPJ asked for our "aha" moments—this was mine. He always does a good job at serving information in a way that is digestible for the audience, so you need not worry that any lambs will be led astray.

Best,

Vilem

> On 2018-07-14, at 13:00, <[hidden email]> <[hidden email]> wrote:
>
> [...]
>
> Message: 4
> Date: Sat, 14 Jul 2018 13:33:31 +0200
> From: MarLinn <[hidden email]>
> To: [hidden email]
> Subject: Re: [Haskell-cafe] What is your favourite Haskell "aha"
> moment?
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Warning: I'll be overly harsh in this mail because I assume some people
> that are new to Haskell might browse this thread now and in the future.
> I don't mean my comments to be considered personal. On the contrary, I
> think some of us can learn for their own teaching endeavours.
>
>> #!/usr/bin/env stack
>> -- stack script --resolver lts-10.1 --install-ghc
>
> Imagine a "newbie" running this script just to see what it does. After
> 15 minutes they'll be disappointed why your small demo took so long to
> build. Only /then/ do they realize that, what is it today, about half a
> gigabyte maybe, of their monthly "high speed" bandwidth and of their
> precious space on the cheap but decade-old hard drive is gone.
>
> Of course you need all that data because there's a ghc in that data, but
> it should say so on the tin. So please never send a script with this
> line to a "newbie" without big warnings so they can make an informed
> decision. Maybe they would want to install ghc at their uni to save on
> that precious bandwidth at home or something similar.
>
> In fact don't even send scripts with this line to seasoned haskellers.
> If your code is compatible with the ghc 8.2.1 on my system, why should
> your script assume I want stack to install 8.2.2 right now?
>
> Of course this behaviour is ingrained in the DNA of stack – after all it
> values convenience for the professional user more than convenience for
> the unprivileged newcomer – but AFAIU it /can/ be persuaded to be more
> inclusive. So especially here, we should maybe try to do that.
>
>>   interact
>>   ( show @Double
>>   . sum
>>   . mapMaybe readMaybe
>>   . words
>>   )
>
> Also, while I do like the scripting possibilities, interact is possibly
> the worst way to introduce a newcomer to it because you can't really
> test it in ghci. Apart from all the other shortcomings it has. It is
> nice in that it hides IO, but…
>
> Again, not meant as an attack, but since we're talking about giving
> newcomers a good experience, I thought these two points important.
>
> Cheers,
> MarLinn
>

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