
Dear Haskellers, since this is my first post, "Hello all" I have a problem with a function taken from class Arrow. arr :: (b -> c) -> a b c To build my own arrow, i need to distinguish between different kinds of b or c. For instance, if b has the form (d,e), i want to construct something different as when having form (d,e,f). Could I get a hint how to express my needs, please! Many thanks in advance Sven Biedermann

Hi Sven,
since this is my first post,
"Hello all"
Welcome!
I have a problem with a function taken from class Arrow.
arr :: (b -> c) -> a b c
To build my own arrow, i need to distinguish between different kinds of b or c. For instance, if b has the form (d,e), i want to construct something different as when having form (d,e,f).
I'm not quite sure I understand what you mean. Are you saying that you you want the input to be either a pair or a triple? Then one possibility would be to wrap up the input in the standard Haskell type "Either". For reference, "Either" is defined like this: data Either a b = Left a | Right b Assume g :: T1 -> T2 -> T h :: T1 -> T2 -> T3 -> T for some specific types T1, T2, T3 and T. Now you can define a function "f": f :: Either (T1,t2) (T1,T2,T3) -> T f (Left (x,y)) = g x y f (Right (x,y,z)) = h x y z Thus "f" "distinguish[es] between different kinds" of input. If it is applied to what essentially is a pair, it will compute a result of type "T" using the function "g", whereas if it is applied to what essentially is a triple it will compute a result using the function "h", again of type "T". Lifting "f" into an arrow yields: arr f :: Arrow a => a (Either (T1,T2) (T1,T2,T3)) T I don't know if that was what you really ment by "construct[ing] something different" depending on the input type? Hope that helps, /Henrik -- Henrik Nilsson School of Computer Science and Information Technology The University of Nottingham nhn@cs.nott.ac.uk This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

On Fri, Jan 27, 2006 at 08:20:07PM +0100, Sven Biedermann wrote:
I have a problem with a function taken from class Arrow.
arr :: (b -> c) -> a b c
To build my own arrow, i need to distinguish between different kinds of b or c. For instance, if b has the form (d,e), i want to construct something different as when having form (d,e,f).
If you want a different instance in each case, then you'll need a different class: arr is polymorphic in b and c. But perhaps there's another way to do what you want. Can you give more details?
participants (3)
-
Henrik Nilsson
-
Ross Paterson
-
Sven Biedermann