[Haskell-cafe] Bird problem 1.6.2 -- is there an easier method?

R J rj248842 at hotmail.com
Wed May 19 18:42:53 EDT 2010


Bird problem 1.6.2 is:
If f :: (a, b) -> c, then define a function "swap" such that:
flip (curry f) = curry (f . swap).
I'd very much appreciate if someone could tell me whether there's a rigorous solution simpler than mine, which is:
Since (.) :: (q -> r) -> (p -> q) -> (p -> r), we have f :: q -> r and swap :: p -> q.  Type unification of f requires q = (a, b) and r = c.
Since f :: (a, b) -> c and curry :: ((l, m) -> n) -> (l -> m -> n), typeunification requires l = a, b = m, and n = c.  Therefore,curry :: ((a, b) -> c) -> (a -> b -> c), and (curry f) :: a -> b -> c.
Since flip :: (s -> t -> u) -> t -> s -> u, type unification requiress = a, t = b, and u = c.  Therefore, flip :: (a -> b -> c) -> b -> a -> c,and flip (curry f) :: b -> a -> c.
Therefore, curry (f . swap) ::  b -> a -> c, and p :: b -> a.  Therefore,swap :: b -> a -> (a, b), and:

swap                       :: b -> a -> (a, b)swap x y                   =  (y, x)

 		 	   		  
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100519/31c1b04c/attachment.html


More information about the Haskell-Cafe mailing list