[Haskell-cafe] Re: Re-order type

André Batista Martins andre_bm at netcabo.pt
Sun Oct 10 07:22:49 EDT 2010

I thanks for the answers.
On this paper, i found this example
"The student has accidental given the arguments of map in the wrong
order. Again, the logged student programs show that this is indeed
a common mistake.
                  (1,8): Type error in application
                     expression : map [1 .. 10] even
                     term : map
                        type : (a -> b) -> [a] -> [b]
                        does not match : [Int] -> (Int -> Bool) -> c
                     probable fix : re-order arguments
The solution i think was in reordering of function arguments and the
elements of a tuple, and the insertion or removal of function arguments.

In general, this problem appears also in sequence of functions. So if we do
the bridge between the functions, and that bridge was one function to
re-order the elements of output to the correct input of next function.

I think that work has been done, in helium compiler.  But i can't identify
the algorithm for this propose.

How i can find the type of one function that i was done, on code, not on


No dia 10 de Outubro de 2010 07:58, Gene A <yumagene at gmail.com> escreveu:

> 2010/10/9 André Batista Martins <andre_bm at netcabo.pt> Said:
>> Might have not been clear, but i will try illustrate .
>> f:: a-> b -> c -> (b,(c,a))
>> f1 ::  c -> a -> d
> -----------------------------
>> I think I would attack this with glue consisting of:
> comb f f1 a b c =  arr (\(a,b,c) -> f a b c) >>> arr (\(b,(c,a))) ->f1 c a)
> $ (a,b,c)
> and yes, have to agree that easier to roll your own if only a few functions
> are like this..
> but should be able to parse the type signatures of the functions involved
> and write a program to automate this process.. using this format as a
> template..
> Actually if you just set it to take all the variables prior to last (->) in
> sig you can put them
> put them together in an uncurried format.. for instance the "a -> b -> c"
> portion would become always \(a,b,c) -> then the function so arr (\(a,b,c)
> -> f a b c) then the term (output) would be the last term in this case
> (b,(c,a)  add that with a "->" between to give that to first part of another
> lambda construction (\(c,a) -> f1 c a) ... arrowizing the whole thing with
> arr (first lambda) >>> arr (second lambda) $ and a tuple from all but the
> last variables in all cases of first function ... so for f it would be
> (a,b,c).  if for some odd reason it was a single it would just become ((a))
> an added parenthesis, which would not hurt a thing for the case where it was
> a sig like f :: a -> b
> So for your case it becomes as shown above:
> comb f f1 a b c =  arr (\(a,b,c) -> f a b c) >>> arr (\(b,(c,a))) ->f1 c a)
> $ (a,b,c)
> and say for:
> f :: a -> (b,c)
> f1:: b -> d
> (\(a) -> f a) >>> (\(b,c) -> f1 b) $ (a)   <- it just harmlessly adds the
> '( ' and ')' around the 'a' even though it doesn't need it as the only
> parameter prior to the last '->'.
> This is probably clear as mud, on first look, but I think a way forward in
> automating from
> this is possible.. I am sure of it.. but it would be at the source code
> level and a string parse and output from that ..
> cheers,
> gene
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101010/a0ce5eb1/attachment.html

More information about the Haskell-Cafe mailing list