Re: How can I implement this arrow? Thanks
What I am trying to do is to use Haskell to simulate some process, and meanwhile collecting information about the data-flow throughout the whole process into the output. The (String, a) example is just a simplified version of that. Thanks for pointing out my mistakes, I will try to do it as a decorated-data combinator. Thanks again, Di, Yu 9.16
From: Derek Elkins <ddarius@hotpop.com> To: Yu Di <diyu01@hotmail.com> CC: haskell@haskell.org, Ashley Yakeley <ashley@semantic.org> Subject: Re: How can I implement this arrow? Thanks Date: Tue, 16 Sep 2003 12:24:17 -0400
On Tue, 16 Sep 2003 01:52:03 -0700 Ashley Yakeley <ashley@semantic.org> wrote:
In article <Sea1-F33yfxRydC3hSs00038d72@hotmail.com>, "Yu Di" <diyu01@hotmail.com> wrote:
Replying to both:
Hi, I want to create an arrow which is essentially
data MyArrow a b = MyArrow ((String, a) -> (String,b))
I don't think this type is an arrow. For a "product arrow", i.e. an instance of Hughes' "Arrow" class with "first" defined, you can define this:
Oh, it's definitely an arrow.
i.e. there is an "information" asscioated with each piece of data (represented by the string),
So make a data type that sticks together something and it's information.
and I want to pass it around.
What's wrong with the support Haskell already has for passing around things? Why do you think you need an arrow?
From how you read the meaning of the MyArrow type, you are apparently misunderstanding what arrows are. Arrows generalize functions. As such things of arrow type are intuitively transformers and the arrow framework standardizes how to stick transformations together to make a larger transformation. The things in an arrow's representation are what's required for the implementations of the transformations. Therefore, things in an arrows representation are, in a sense, "owned" by the arrow computation. This is evidenced by a) arrows have a fully polymorphic type, they place no restrictions on their input; within the computation, the String in MyArrow is not even visible let alone required to be provided, and b) the above arrow is the State arrow specialized to Strings. The String is the state and is owned by the computation. You are having trouble defining 'first' as you'd like because what you want is to duplicate the state of the computation. -The- (there is only one at any time) String being passed around isn't associated with the objects.
From the sounds of it you simply want a combinator library that operates on some decorated data. A monad or arrow may be useful to support that, e.g. the environment monad, but a monad/arrow isn't that. You haven't really given much detail to what you're ultimately trying to achieve so I can't really provide much advice.
_________________________________________________________________ Use custom emotions -- try MSN Messenger 6.0! http://www.msnmessenger-download.com/tracking/reach_emoticon
On Tue, 16 Sep 2003 14:32:48 -0500 "Yu Di" <diyu01@hotmail.com> wrote:
What I am trying to do is to use Haskell to simulate some process, and meanwhile collecting information about the data-flow throughout the whole process into the output. The (String, a) example is just a simplified version of that. Thanks for pointing out my mistakes, I will try to do it as a decorated-data combinator.
Thanks again,
If all you want to do is trace the execution of some computation, you can use the Writer/Output monad. This will associate the outputting with the functions that process the simulation. It looks something like, foo a b = do tell ("Entering foo with "++show a++" "++show b) doStuff a someMoreStuff b tell "Leaving foo" You can write things other than strings.
On Tue, Sep 16, 2003 at 02:32:48PM -0500, Yu Di wrote:
What I am trying to do is to use Haskell to simulate some process, and meanwhile collecting information about the data-flow throughout the whole process into the output. The (String, a) example is just a simplified version of that. Thanks for pointing out my mistakes, I will try to do it as a decorated-data combinator.
This sounds a bit like the example in http://www.soi.city.ac.uk/~ross/talks/fop.4.ps.gz The idea is to define your network as a generic arrow, and instantiate it differently for different interpretations. For simulation, one can use Stream i -> Stream o, though there are other possibilities. To get a map, you use a state transformer (with the map as the state), and pass edge labels through the arrows. I think the reason you're getting in a tangle is that you're trying to do both with the same interpretation.
participants (3)
-
Derek Elkins -
Ross Paterson -
Yu Di