How can I implement this arrow? Thanks

Yu Di diyu01 at hotmail.com
Mon Sep 15 22:57:54 EDT 2003


Hi, I want to create an arrow which is essentially

data MyArrow a b = MyArrow ((String, a) -> (String,b))

i.e. there is an "information" asscioated with each piece of data 
(represented by the string), and I want
to pass it around. But I have a problem about how to define "pure" and 
"first". At first, I declared

pure f = MyArrow (\(s, x) -> (s, f x))
first (MyArrow f) = MyArrow (\(s, (x, y)) -> let (s', z) = f (s, x) in (s', 
(z, y)))

this seems to work, but then I begin to have problems with the 
"data-plumbing" pure arrows, e.g. in

pure (\x -> (x, x)) >>> first someArrow >>>> pure (\(_, x) -> x)

Ideally, this arrow will preserve whatever information I put there for the 
input, but because "first
someArrow" will change the whole information associated with the pair of 
result, I can't find any
way to let "pure (\(_, x)->x)" (which is an extremely generic function) 
retrieve the part of information for the second piece in the pair tuple.

Of course I can create specialized arrows for the tasks \x -> (x, x) and 
\(_, x) -> x which passes the information around, but this will become 
tedious as I will have to define specialized arrows for a lot of similar 
tasks one by one, and I won't be able to use the arrow pre-processor at all.

So how can I implement this? Thanks very much!

Di, Yu
9.15

_________________________________________________________________
Get 10MB of e-mail storage! Sign up for Hotmail Extra Storage.  
http://join.msn.com/?PAGE=features/es



More information about the Haskell mailing list