-
Notifications
You must be signed in to change notification settings - Fork 5
Notes for Week 2 Getting Started
Links:
- Chapter 2 summary
- Some basic functions to get you started
- General syntax overview
- Hoogle - A Haskell API search engine
- Hayoo - Another Haskell API search engine
- Eric Meijer's functional tutorial on FP basics
- List Comprehensions in different languages
Exercises:
-
Rewrite the following with the use of the notElem (not an element of) function:
>> [x | x <- [10..20], x /= 13, x /= 15, x /=19]
-
Write the replicate function, in terms of repeat and take. Eg:
>> replicate 3 10 == ??
-
Write the sum of the numbers in each sublist of xxs without flattening it:
>> let xxs = [ [1,3,5,2,3,1,2,4,5],[1,2,3,4,5,6,7,8,9],[1,2,4,2,1,6,3,1,3,2,3,6] ]
Eg: [ [x], [y], [z] ], where x,y,z are totals.
-
What is the type of the tuple in the following expression:
>> ([1,2,3], "hello", ['a','b'], (1, 'c', True))
Eg. (True, 'a') is a (Bool, Char)
Questions raised during the group:
-
Xor function I found this nice blog post on multiple implementations of the xor function.
-
Nested if-then-else statements:
if (a && b) then not a else if (a || b) then True else False
-
Max size of tuples:
There is no upper bound on the size of a tuple, but some Haskell implementations may restrict the size of tuples, and limit the instances associated with larger tuples. However, every Haskell implementation must support tuples up to size 15, together with the instances for Eq, Ord, Bounded, Read, and Show. The Prelude and libraries define tuple functions such as zip for tuples up to a size of 7.
As of GHC 6.12.2, the maximum size of a tuple is 62: