2

The curry-uncurry isomorphisms can be expressed as invertible maps between various kinds of "higher-order" programs in the Reader monad (ignoring wrappers to keep things concise):

type R r a = r -> a

uncurryR :: R r (R s a) -> R (r, s) a
uncurryR m (r, s) = m r s

curryR :: R (r, s) a -> R r (R s a)
curryR m r s = m (r, s)

I have become interested in a State-monadic version of uncurryS, as follows:

type S r a = r -> (a, r)

uncurryS :: S r (S s a) -> S (r, s) a
uncurryS m (r, s) = (v, (t, u))
  where (n, t) = m r
        (v, u) = n s

Of course, unlike uncurryR, unCurryS isn't an isomorphism: S (r, s) a is in general a much "larger" type than S r (S s a).

I'm an academic linguist, and without going into too much detail, the difference between R and S with respect to their "uncurrying" operations -- i.e., whether they're isomorphisms -- turns out to be consequential for thinking about various problems in the formal semantics of natural language (believe it or not!).

In general, when a construct looks relevant for natural language semantics, I've found it helpful to chase down connections in computer science and category theory, to the extent that I can. To that end, I would be very interested to know of any related issues have been discussed, either in the functional programming literature or in more categorical terms. I am sorry I can't be much more specific, but I appreciate any help and any pointers.

SEC
  • 799
  • 4
  • 16
  • This question is far too vague - the actual problem ("without going into too much detail" - this is far too little detail) is unclear. At best it seems to be a request for resources (off-topic). Besides, `StateT s (StateT s' m) a` and `StateT (s, s') m a` *are* isomorphic, which is really what you're observing - it's just a coincidence that `ReaderT r (ReaderT r' Identity) a` and `ReaderT r Identity (ReaderT r' Identity a)` are also isomorphic, so you get the more specific version of the isomorphism for `Reader`. – user2407038 Sep 12 '16 at 20:42
  • 1
    @user2407038 `S r (S s a)` is not the same as `StateT r (State s) a`: in particular, `S r (S s a)` must commit to an updated `r` before inspecting the `s` state. So `S r (S s a)` and `S (r, s) a` are *not* isomorphic! – Daniel Wagner Sep 12 '16 at 22:01
  • 1
    You may be interested in the related question, [Applicatives compose, monads don't](http://stackoverflow.com/questions/7040844/applicatives-compose-monads-dont). – Daniel Wagner Sep 12 '16 at 22:03
  • @user2407038 However, I agree with your assessment that this kind of question is generally considered off-topic here on StackOverflow. I might suggest IRC (if you hop on when the CT heavy hitters are around) or one of the mailing lists (if you're not sure you can get on at the right time) as more appropriate fora for this kind of discussion. – Daniel Wagner Sep 12 '16 at 22:06
  • Thanks, I reckon you're right. A bit more about why I care: In linguistics there's something of a 'debate' between people who represent the meanings of sentences with pronouns as functions from environments to booleans (where environments are sequences of values, like in a Tarskian semantics for first-order logic), and people who prefer the curry'd version. Given the curry-uncurry isomorphisms, it's hard to imagine this fracas has empirical content. But in richer type-spaces like `S` (which are [useful](http://www.indiana.edu/~iulg/nlcsslides/MNLS.pdf) in semantics), it seems like it might. – SEC Sep 13 '16 at 14:21

0 Answers0