Monday, September 22, 2008

A bit of a snag

Well it seem that I have hit a bit of a snag in implementing the arrow combinators. I can't for the life of me figure out how to write the loop or the ( ||| ) combinator. The later is problem with my understanding of how to use the Choice type and discriminating unions. But with the former I am genuinely lost. Here is the Haskell signature for loop:

Class Arrow arr => ArrowLoop arr where
loop :: arr (a,c) (b,c) -> arr a b

So in F# that should be either:

val loop : Arrow<('a*'c),('b*'c)> -> Arrow<'a,'b>

or :

val loop: ArrowLoop<('a*'c),('b*'c)> -> Arrow<'a,'b>

Again in Haskell the loop combinator for functions is defined as:

instance ArrowLoop (->) where
loop f a = b
where (b,c) = f (a,c)

Now how would you implement that in F#?

1 comment:

Unknown said...

let loop (f:Arrow<('b * 'd),('c * 'd)>) =
let rec d = d
arr (fun b ->
let (c,_) = f.run (b,d)
c)
But whether it makes sense, I don't know.