I am trying to revise for my functional programming exam, and am stumped on the first questions on past papers, and yes, we arent allowed solution sheets, here is an example of the 1st question on a past paper.
For each of the following expressions give its type in Haskell (for an expression that has many types, just give one type).
(True, "hello", 42) [42, 4, 2] length [True] filter even
I think personally that the answer for one and two would be a tuple of bool, String and int and a list of ints respectively, is this correct to assume? and secondly how would you answer 3 and 4, i am sure length True just outputs a list of all elements that are of that length, and that filter even just alters a list of ints to a list that are of all even numbers, though how could i show this as an answer?
If you want to get types of variables offline with ghci you have to type
:texpressionif you want to create variables in ghci, you have to use let without using ‘in’ (as in do notation for monads, I don’t know if you have seen them yet) :
letvar= exprIf you check it all by yourself, you should be able to remember it more easily for your exams. (good luck for it ;))