Valery V. Vorotyntsev wrote:
On 1/23/08, David Menendez <[EMAIL PROTECTED]> wrote:
On Jan 23, 2008 12:20 PM, Valery V. Vorotyntsev <[EMAIL PROTECTED]> wrote:
I've built GHC from darcs, and...
Could anybody tell me, what's the purpose of Arrow[1] not having `>>>'
method?
It's derived from the Category superclass.

Yes, it is.

The right question: how to build `arrows' in such circumstances?

Here go 2 changes I made to `CoState.hs' accompanied by the
error messages. :) Unfortunately, I'm not arrow-capable enough to
make _proper_ changes to the code and satisfy GHC... Any help?


Well, without looking at your code, generally all you have to do is

1) move the definition of (>>>) to Category and rename it to (.) after flipping the arguments.
2) define the id method of Category which is just (arr id) or returnA.

So essentially

instance Arrow (Foo a) where
  a >>> b = compose a b
  pure f = ...
  first a = ...

becomes

instance Arrow (Foo a) where
  pure f = ...
  first a = ...

instance Category (Foo a) where
  id = arr id
  a . b = compose b a

That's it. It's too bad there's no way to do this automatically in the libraries, but it could be noted in the API docs.

Pete

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change #1:

$ darcs w Control/Arrow/Transformer/CoState.hs
What's new in "Control/Arrow/Transformer/CoState.hs":

{
hunk ./Control/Arrow/Transformer/CoState.hs 23
+import Control.Category ((>>>))
}

--------------------------------------------------
Error #1:

Control/Arrow/Transformer/CoState.hs:29:7:
    `>>>' is not a (visible) method of class `Arrow'
Failed, modules loaded: Control.Arrow.Operations.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change #2:

$ darcs diff -u Control/Arrow/Transformer/CoState.hs
--- old-arrows/Control/Arrow/Transformer/CoState.hs     2008-01-24
14:54:29.852296559 +0200
+++ new-arrows/Control/Arrow/Transformer/CoState.hs     2008-01-24
14:54:29.852296559 +0200
@@ -20,12 +20,13 @@

 import Control.Arrow
 import Control.Arrow.Operations
+import Control.Category ((>>>))

  newtype CoStateArrow s a b c = CST (a (s -> b) (s -> c))

  instance Arrow a => Arrow (CoStateArrow s a) where
        arr f = CST (arr (f .))
-       CST f >>> CST g = CST (f >>> g)
+--     CST f >>> CST g = CST (f >>> g)
        first (CST f) = CST (arr unzipMap >>> first f >>> arr zipMap)

  zipMap :: (s -> a, s -> b) -> (s -> (a,b))

--------------------------------------------------
Error#2:

Control/Arrow/Transformer/CoState.hs:27:0:
    Could not deduce (Control.Category.Category (CoStateArrow s a))
      from the context (Arrow a)
      arising from the superclasses of an instance declaration
                   at Control/Arrow/Transformer/CoState.hs:27:0
    Possible fix:
      add (Control.Category.Category
             (CoStateArrow s a)) to the context of
        the instance declaration
      or add an instance declaration for
         (Control.Category.Category (CoStateArrow s a))
    In the instance declaration for `Arrow (CoStateArrow s a)'
Failed, modules loaded: Control.Arrow.Operations.

Thank you.


_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to