[Haskell-cafe] arr f

Sven Biedermann Sven.Biedermann at biedermann-consulting.de
Sat Jan 28 10:28:40 EST 2006

Hello Henrik & Ross,

Man thanks for your input. I have realised that I should have explained
my problem better.

So, I try...

I want to create a datatype like this:

	data D a b = DepVoid (a->b)   | -- a = ()
			 DepSingle (a->b) | -- a = a      simple ones
			 DepPair (a->b)   | -- a = (c,d)
			 DepTriple (a->b) | -- a = (c,d,e)
			 DepFun (a->b)      -- a = (c->d)

Its easy to construct them:

	mkArrVoid :: (() -> c) -> D () c
	mkArrVoid f	= DepVoid f

	mkArrPair :: ((a,b) -> c) -> D (a,b) c
	mkArrPair f = DepPair f  


Now I want to make D an instance of Arrow:

	instance Arrow (D) where -- my problems stems from
		arr f = ???

I have no clue to glue the mkArr* functions together to reach what I
want: a different Dep* for different functions f.
What can I pattern match, here? What can I do else?



-----Original Message-----
From: Henrik Nilsson [mailto:nhn at Cs.Nott.AC.UK] 
Sent: Freitag, 27. Januar 2006 21:46
To: Sven Biedermann
Cc: haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] arr f

Hi Sven,

 > 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).

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

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


    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 Nilsson
School of Computer Science and Information Technology The University of
Nottingham nhn at cs.nott.ac.uk

This message has been checked for viruses but the contents of an
may still contain software viruses, which could damage your computer
you are advised to perform your own checks. Email communications with
University of Nottingham may be monitored as permitted by UK

More information about the Haskell-Cafe mailing list