Basic Functions Flashcards

1
Q

What is pattern matching?

A

NOT PATTERN MATCHING:
factorial if n <= 1 then 1
else n*factorial(n-1)

PATTERN MATCHING:
factorial 0 = 1
factorial n = n * factorial(n-1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Int to String pattern matching

A

IntToStr :: Int -> String
IntToStr 1 = “one”
IntToStr 2 = “two”
… etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly