1
0
Fork 0
pr3-sose2026-fork/haskell/01-expressions/README.md

1.6 KiB

Haskell - Expressions

The following illustrates some haskell basics. It can be reproduced using ghci.

Types, Literals, and Constants along with Arithmetic and Boolean Operations

Expression Type (:t) Value Comment
2 Num a => a 2
2.03 Fractional a => a 2.3
'c' Char 'c'
"hallo" String "hallo"
True Bool True
x=5 Num a => a 5 Constant named x
2 + 3 Num a => a 5 Similar -,*,^
2 / 3 Fractional a => a 0.6666666666666666
1 > 2 Bool False Similar <, <=, >=, ==, /=
True && False Bool False Similar ||,not
((2+3)*5 > 1) || not (1 > 2) Bool True Right part is not evaluated due to lazy evaluation

Unary Functions

Expression Type (:t) Value Comment
sqrt(4) Floating a => a 2.0
sqrt 4 Floating a => a 2.0 Similar abs,negate,signum,recip
sqrt Floating a => a -> a
sqrt 3^2 + 4^2 Floating a => a 19.0
sqrt (3^2 + 4^2) Floating a => a 5.0
negate(sqrt (3^2 + 4^2)) Floating a => a -5.0
negate $ sqrt (3^2 + 4^2) Floating a => a -5.0 Function application operator $
(negate . sqrt) (3^2 + 4^2) Floating a => a -5.0 Function composition operator . Reads negate after negate . sqrt
(negate . length) "hallo" Int -5
negatedRoot = negate . sqrt Floating c => c -> c Constant named negatedRoot

Binary Functions

Tuples

Strings

Control Structures

Lists