Question about implementation of a " arrow
Yu Di
diyu60607 at yahoo.com
Mon Sep 15 15:11:12 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. And often the arrow's processing
logic will depend on the input information, therefore
a monad-style
data MyArrow a b = MyArrow (a -> (String, b))
will not work.
Now I have a problem with the definition of "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)" retrieve the PART of
information for the second piece in the pair tuple.
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
More information about the Haskell
mailing list