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)
2
Q
Int to String pattern matching
A
IntToStr :: Int -> String
IntToStr 1 = “one”
IntToStr 2 = “two”
… etc