As you may have noticed I study computer science and therefore I would like to write some things regarding the studies on my blog. Of course the focus is mainly music and environmental but technology is also a big part of our life so… Here it comes.
Haskell is a programming language that is functional and my experience of programming is, before entering the program, mainly Java, an imperative language. And also a lot of webbprogramming as a hobby but it is not real programming in this sense.
Functional programming can shortly be described as programming with no side-effects.
But even side effects are possible since you for example will sometime need input and output, so called I/O. This type of programming in Haskell is called inpure.
This picture I found on Internet makes me a little bit sceptical about I /O monad:
(pic from Haskell guide)
What sites you should check out when programming with Haskell :
- Hoogle. Oh yes, stop googling and start hoogling !
- Learn you a Haskell. An online book about Haskell. Learn you a Haskell for great good. Well, well. I’m just doing it to pass the course 🙂 The examples in the book are ethically miserable but you can learn a lot from here.
- Haskell Wiki. The how to guides of Haskell.
- A Haskell guide here.
Have you used another site that should be on the list? Let me know and I will update!
The fun of Haskell
What I find intriguing about Haskell, as my first functional programming language is how compact the expressions can be. Following syntactic structures are very cool:
A simple and very clarifying example is lucky seven:
lucky :: (Integral a) => a -> String
lucky 7 = “LUCKY NUMBER SEVEN!”
lucky x = “Sorry, you’re out of luck, pal!”
The example is from LearnyouaHaskell.
bmiTell :: (RealFloat a) => a -> String bmiTell bmi
| bmi <= 18.5 = “Underweight”
| bmi <= 25.0 = “Normalweight”
| bmi <= 30.0 = “Overweight”
| otherwise = “Check your input again.”
The example is from LearnyouaHaskell and the program feedback is modified because the original is hideous (unethical), supposedly fun but I think they should rethink it. Whatever, check the cool guards!
The input/output (I/O) of Haskell is called inpure programming, since it is programming with side effects.
The classic “Hello world!” in Haskell:
main = putStrLn “hello, world”
Learn you a good Haskell has a chapter with Input and Output.
Is Haskell my new passion in life?
No, actually but I am happy to have experienced it. I still would say I totally prefer imperative programming like Java, it makes more sense to me.
Publicerar detta inlägg bara på engelska eftersom alla sidor som ovan nämns är på engelska och även vår undervisning.