[L03 StateT] Questions - SPOILER ALERT

50 views
Skip to first unread message

Riaan Rottier

unread,
Jun 8, 2013, 10:16:19 PM6/8/13
to haskell-...@googlegroups.com
I finally got round to StateT and have a few question:

Question 1:
----------------
For Exercise 1 the answer I get is:

  fmaap g (StateT s) = StateT (\s' -> let m = s s' in fmaap (\(a,s'') -> (g a,s'')) m)

and I have no clue how to even relate that to Tony's:

  fmaap f (StateT k) = StateT (fmaap (\(a, t) -> (f a, t)) . k)

Any ideas?

I am in the same situation for Ex2 but I think if I get Ex 1 then I will be able to figure out 2 by myself.

Thanks
Riaan

Charles O'Farrell

unread,
Jun 9, 2013, 1:26:36 AM6/9/13
to haskell-exercises
Hi Riaan,
They're identical, but Tony has just used composition (.) and currying, also known as point-free. Not sure if this helps, but...

fmaap g (StateT s) = StateT (\s' -> let m = s s' in fmaap (\(a,s'') -> (g a,s'')) m)
fmaap g (StateT s) = StateT (\s' -> fmaap (\(a,s'') -> (g a,s'')) (s s'))
fmaap g (StateT s) = StateT (\s' -> (fmaap (\(a,s'') -> (g a,s'')) . s) s') -- (.) :: (b -> c) -> (a -> b) -> a -> c
fmaap g (StateT s) = StateT (fmaap (\(a,s'') -> (g a,s'')) . s) -- curry the last argument
fmaap f (StateT k) = StateT (fmaap (\(a, t) -> (f a, t)) . k) -- different letters, same thing

Does that make sense?
Charles


Riaan

--
You received this message because you are subscribed to the Google Groups "haskell-exercises" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-exerci...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Riaan Rottier

unread,
Jun 11, 2013, 6:23:04 PM6/11/13
to haskell-...@googlegroups.com
Perfect sense. Thanks

Riaan

Reply all
Reply to author
Forward
0 new messages