So... I have written this to get 5 rectangles from user :
rectangles <- sequence . take 5 . cycle [getRect]
But it doesn't work. Then I have refactored it as this which is shorthand for writing braces:
rectangles <- sequence $ take 5 $ cycle [getRect]
I'm not sure why my function compostion is not valid. I would expect it to work like this if I'm to translate it to "real world" function, no? :
sequence(take(5 , cycle(getRect)))
[EDIT]
I understand that (.) is for function composition and $ for application but my composition should return function and than apply [getRect] to it. Should it not?
I'm looking at this from purely mathematical standpoint. Let's say that
cycle : a -> b
take 5 : b -> c -- partially applied
sequence : c -> d
So why doesn't my composition work? It should be a function with argument [getRect] like this :
(sequence . take 5 . cycle)([getRect]) : a -> d
Where a
is [getRect] and d
is result of IO action.