(a -> [b]) vs. [a -> b]
Are (a -> [b]) and [a -> b] isomorphic? I'm trying to construct a function f :: (a -> [b]) -> [a -> b] that is the (at least one-sided) inverse of f' :: [a -> b] -> a -> [b] f' gs x = map ($ x) gs It seems like it should be obvious, but I haven't had any luck with it yet. Any help is greatly appreciated. Thanks, Chad
Chad Scherrer said:
Are (a -> [b]) and [a -> b] isomorphic?
I'm trying to construct a function
f :: (a -> [b]) -> [a -> b]
that is the (at least one-sided) inverse of
f' :: [a -> b] -> a -> [b] f' gs x = map ($ x) gs
It seems like it should be obvious, but I haven't had any luck with it yet. Any help is greatly appreciated.
Have a look at this post and it's follow-ups: http://www.haskell.org/pipermail/haskell-cafe/2006-December/020041.html
Chad Scherrer wrote:
Are (a -> [b]) and [a -> b] isomorphic? I'm trying to construct a function
f :: (a -> [b]) -> [a -> b]
that is the (at least one-sided) inverse of
f' :: [a -> b] -> a -> [b] f' gs x = map ($ x) gs
Anything better than this? f g = [\x -> g x !! n | n <- [0..]] -Yitz
Oops, I thought I had sent a response to the cafe, but it looks like it just went to Matthew. Unfortunately, I was trying to give a simplification of the real problem, where the monad is STM instead of []. Based on apfelmus's observation of why they can't be isomorphic, I'm guessing I'm out of luck. http://www.haskell.org/pipermail/haskell-cafe/2006-December/020041.html So in reality, I'm trying to construct something like f :: (a -> STM b) -> STM (a -> b) I just figured it was a general monadic kind of problem, more simply expressed using lists. But the (!!) solution doesn't make sense in this context. On 2/2/07, Yitzchak Gale <gale@sefer.org> wrote:
Chad Scherrer wrote:
Are (a -> [b]) and [a -> b] isomorphic? I'm trying to construct a function
f :: (a -> [b]) -> [a -> b]
that is the (at least one-sided) inverse of
f' :: [a -> b] -> a -> [b] f' gs x = map ($ x) gs
Anything better than this?
f g = [\x -> g x !! n | n <- [0..]]
-Yitz
-- Chad Scherrer "Time flies like an arrow; fruit flies like a banana" -- Groucho Marx
On 2/2/07, Chad Scherrer <chad.scherrer@gmail.com> wrote:
So in reality, I'm trying to construct something like f :: (a -> STM b) -> STM (a -> b)
I just figured it was a general monadic kind of problem, more simply expressed using lists. But the (!!) solution doesn't make sense in this context.
Perhaps this will work for you: f x = join . liftM f This typechecks, and seems to work as expected, e.g.: Prelude Control.Concurrent.STM Control.Monad> atomically (f readTVar (newTVar 'a')) 'a' /g -- It is myself I have never met, whose face is pasted on the underside of my mind.
Uh, apologies. I got confused between reading your post and playing for a while, and answered the wrong question. /g On 2/2/07, J. Garrett Morris <trevion@gmail.com> wrote:
On 2/2/07, Chad Scherrer <chad.scherrer@gmail.com> wrote:
So in reality, I'm trying to construct something like f :: (a -> STM b) -> STM (a -> b)
I just figured it was a general monadic kind of problem, more simply expressed using lists. But the (!!) solution doesn't make sense in this context.
Perhaps this will work for you:
f x = join . liftM f
This typechecks, and seems to work as expected, e.g.:
Prelude Control.Concurrent.STM Control.Monad> atomically (f readTVar (newTVar 'a')) 'a'
/g
-- It is myself I have never met, whose face is pasted on the underside of my mind.
-- It is myself I have never met, whose face is pasted on the underside of my mind.
Chad Scherrer wrote:
Unfortunately, I was trying to give a simplification of the real problem, where the monad is STM instead of []. Based on apfelmus's observation of why they can't be isomorphic, I'm guessing I'm out of luck.
http://www.haskell.org/pipermail/haskell-cafe/2006-December/020041.html
So in reality, I'm trying to construct something like f :: (a -> STM b) -> STM (a -> b)
Indeed, such an f most likely does not exist. What is the task you tried to solve with the help of f? I guess that either there is a way without or it just cannot be solved for mathematical reasons. Regards, apfelmus
On Sat, Feb 03, 2007 at 10:13:17AM +0100, apfelmus@quantentunnel.de wrote:
Chad Scherrer wrote:
So in reality, I'm trying to construct something like f :: (a -> STM b) -> STM (a -> b)
Indeed, such an f most likely does not exist.
Yes, consider: f readTVar :: STM (TVar c -> c) That would be pretty dangerous. Best regards Tomasz
participants (6)
-
apfelmus@quantentunnel.de -
Chad Scherrer -
J. Garrett Morris -
Matthew Brecknell -
Tomasz Zielonka -
Yitzchak Gale