1.- What type are the following values:
['a','b','c'] :: [Char]
('a','b','c') :: (Char,Char,Char)
[(False,'0'),(True,'1')] :: [(Bool,Char)]
([False, True],['0','1']) :: ([Bool],[Char])
[tail, init, reverse] :: [[a] -> [a]]
-- 2.- What are the type of the following functions:
second :: [a] -> a
second xs = head (tail xs)
swap :: (a,b) -> (b,a)
swap (x,y) = (y,x)
pair:: a -> b -> (a,b)
pair x y = (x,y)
double :: (Num a) => a -> a
double x = x*2
palindrome :: (Eq a) => [a] -> Bool
palindrome xs = reverse xs == xs
twice :: (a -> a) -> a -> a
twice f x = f (f x)
I think you're missing a great opportunity here. Please ask questions about all the thing that Erik is presenting and you don't understand. I bet you would get a lot of help in the forum. That would help a lot of people that might be having the same issues
as you. Also it would give Erik an inside of what concepts are difficult to grasp and help him to better present future chapters.
Another think hat you can do is read the chapter of the book that Erick is going to present in advance. That way you know what's going to be covered. If you don't have the book, the slides are here:
Thanks exoteric. My original solution for init' didn't use composition until I saw the lecture and Erik started talking about function composition (yes, I did the exercises from the book before the lecture ). I'm not sure if good at this point of the
lecture to introduce pointfree style. But how am I to say
This was my original solution:
init’ xs = reverse (tail (reverse xs))
Which I think people not familiar with Haskell would understand better than
init’ = reverse . tail . reverse
I say this, because it took me a while to understand what was going on with the second definition and why the parameter was implicit.
I think you're being too harsh on F#. F# is an excellent bridge for people that want to learn functional programming. I has all the familiar things that an imperative programmer expects like mutable variables, the “for” loop, objects, Visual Studio support.
But once you let go the training wheels, you have access to all the benefits of a functional language.