Trying second time Haskell is awesome

I have tried first time Haskell in 2023 Feb - March.
I used meanwhile Elm mainly.
There is now in VSCode quite good support with plugins to Haskell.
Reading the book and doing something in ghci by myself at the same time helps learning.
Here is a modified example taken from the book, an interactive BMI-calculator.
It works Ok in local system:

MacBook-Pro myhaskell % ./bmicalc
"Input weight KG "
65
"Input height CM"
185
Weight 65.0 kg Height 1.85 m
 Your BMI value 18.99
You're supposedly normal. Pffft, I bet you're ugly!
*****
MacBook-Pro myhaskell % ./bmicalc
"Input weight KG "
55
"Input height CM"
190
Weight 55.0 kg Height 1.90 m
 Your BMI value 15.24
You're underweight, you emo, you!
*****

Unfortunately, it does’nt work on the playground, apparently because of readLn, so as last year.

11 Likes

Hello! Haskell Playgorund doesn’t support user input, and it’s not currently planned, I think. A bit more interactive way to try Haskell online is via repl.it. E.g I put your code here, and it seems to work: lyah-bmi-app - Replit (I think you need to register with them and click green Fork button to be able to play with it). By default, when you hit Run there, they open ghci and run the main function, if present, so this is close although not the same as you want, I think. Also, ghci has a bit different defaults, so I had to add a language pragma at the first line.

On the topic of the book: I suggest to use a much modernized version of LYAH here instead: https://learnyouahaskell.github.io/

3 Likes

Even the color codes don’t work in Haskell playground.
Leaving out the inputs and colors it looks like this.
The version saved in Replit does not work for me. I don’t see any Run-button - just only the haskell source.
However, the most important thing of this study case is still visible in the source - how to construct some chain of conditions in a simple way witout if-then-else and how to complete it optionally with some function using where.

1 Like

For repl.it: did you click Fork first?

Everything works now fine since I signed up to replit.com, also the text colors are Ok.

1 Like

Good to hear, enjoy Haskell!