Post

Haskell Way

Haskell Way

setting up on dev environment

1
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

It will ask install ghcup, ghc, stack, cabal by default and ask you if you want to install pre-releases (I simply answered no to those). You will also want hls for integration with vscode (or any other editor of your choice).

the beginning

In haskell, there is no concept of statements. Everything in haskell is an expression. An expression has a value and a type.

ExpressionValueType
TrueTrueBool
“adi”“adi”Char
“adi” ++ “ raj”“adi raj”Char
not FalseTrueBool

Expressions consists of functions applied to arguments. Arguments can be function application or function itself. In haskell, function application we write the name of function followed by arguments with space between distinct argumnets. So, f a b is equivalent to f(a, b) in C-style languages. Parenthesis serve different purpose here; such as determining the order of the function application.

1
2
3
4
5
f g (h 1)
f (g h) 1
f (g h 1)
f (g (h 1))
f g h 1

is equivalent to following in the C-style languages:

1
2
3
4
5
f(g, h(1))
f(g(h), 1)
f(g(h,1))
f(g(h(1)))
f(g, h, 1)

Some functions are given special treatment as operator and given special character like + for addition, ++ for string concatenation. So, operators are generally binary and require arguments between them. Also, precendence of operators are less than other functions. Like

1
2
f a + g a
f ( a + g b)

is equivalent to following C-style expression

1
2
f(a) + g(b)
f(a, g(b))

In haskell, function application is left associative that means f g h 1 is equivalent to (((f g) h) 1).

some primitives types

TypeUseOperationsLiterals
IntNumber type (signed, 64-bit)+, -, *, div, mod-3,3,0
IntegerUnbounded number type+, -, *, div, mod9999999999999999999, -2, 0, 3
DoubleFloating point number 64 bit+, -, *, /3.14, 3.12e2, 1.2
String (aka [ Char ])List of character++, reverse“a”, “adi” , “”
BoolTruth values||, &&, notTruth, False
This post is licensed under CC BY 4.0 by the author.