[Haskell-cafe] What is your favourite Haskell "aha" moment?
Vilem-Benjamin Liepelt
vl81 at kent.ac.uk
Sun Jul 15 12:12:19 UTC 2018
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, <haskell-cafe-request at haskell.org> <haskell-cafe-request at haskell.org> wrote:
>
> [...]
>
> Message: 4
> Date: Sat, 14 Jul 2018 13:33:31 +0200
> From: MarLinn <monkleyon at gmail.com>
> To: haskell-cafe at haskell.org
> Subject: Re: [Haskell-cafe] What is your favourite Haskell "aha"
> moment?
> Message-ID: <c7a00886-f32b-c4ae-617d-450394278b58 at gmail.com>
> 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
>
More information about the Haskell-Cafe
mailing list