Gaining Intuition for Reader

112 views
Skip to first unread message

Kevin Meredith

unread,
Mar 12, 2015, 10:01:42 PM3/12/15
to nict...@googlegroups.com
I'm working on the `Apply.hs` exercise.

I don't have a good intuition for how to define `Apply`. 

instance Apply ((->) t) where
  (<*>) ::
    ((->) t (a -> b))
    -> ((->) t a)
    -> ((->) t b)
  (<*>) = error "todo"

What's the meaning of ((->) t (a -> b))?

If you could please give me some intuition.

Luis Fernando Milano Oliveira

unread,
Mar 13, 2015, 11:53:12 AM3/13/15
to nict...@googlegroups.com
Hello, Kevin.

I'm also working through the course, currently I'm working on the "StateT.hs" exercises, so I've been where you are.

About your question, the first thing to notice is that '((->) t' is nothing more than the function type constructor partially applied to some value 't'.
It is in prefix notation, but we could think about that signature this way(although it's syntactically incorrect):
(<*>) :: (t -> (a -> b)) -> (t -> a) -> (t -> b)

So, the first argument you have (t -> (a ->b)) is a function that takes a 't' argument and gives another function, (a -> b), back.
The second argument (t -> a) is a function that also takes a 't' as argument and fives a 'a' back (tip: it's the same 't' the first function took).

If you remember the signature for function composition -  (.) - it goes like this:
(.) :: (b -> c) -> (a ->b) -> (a -> c)
It's somewhat similar to that from apply (<*>).

From this I think you could gain some intuition and work on your solution.

I hope this helps!

Kevin Meredith

unread,
Mar 14, 2015, 3:07:59 PM3/14/15
to nict...@googlegroups.com
That answered helped me out a lot. Thanks!
Reply all
Reply to author
Forward
0 new messages