Trouble defining `instance Arrow SF'

In trying to follow along with `Programming with Arrows' by John Hughes, I'm entering the following code: 1 -- Taken from `Programming with Arrows'. 2 3 module SF where 4 5 import Control.Arrow 6 7 newtype SF a b = SF {runSF :: [a] -> [b]} 8 9 instance Arrow SF where 10 arr f = SF (map f) 11 SF f >>> SF g = SF (f >>> g) and getting the following error from GHCI: GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :load SF [1 of 1] Compiling SF ( SF.hs, interpreted ) SF.hs:11:10: `>>>' is not a (visible) method of class `Arrow' Failed, modules loaded: none. Can anyone help? Thanks, -db

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
SF.hs:11:10: `>>>' is not a (visible) method of class `Arrow' Failed, modules loaded: none.
In the base package Arrows are defined a bit different from what you some times see in the literature. I also stumbled over this once. The (>>>) operator is just a synonym for (.) from Control.Category. Note that (.) is not the same (.) as in Prelude. class Category cat where Control.Category.id :: cat a a (Control.Category..) :: cat b c -> cat a b -> cat a c class Category a => Arrow a where arr :: (b -> c) -> a b c first :: a b c -> a (b, d) (c, d) f >>> g = g . f your implementation would probably look something like this. module Main where import Control.Arrow import Control.Category as Cat newtype SF a b = SF {runSF :: [a] -> [b]} instance Category SF where id = SF Cat.id SF f . SF g = SF (f Cat.. g) instance Arrow SF where arr f = SF (map f) first (SF f) = SF (unzip >>> first f >>> uncurry zip) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJOqWTQAAoJEDLsP+zrbatWcmgP/j5DXHq5lEUKM2CHkfLuoVeQ wJkRjsH9lRKVS/LHsfYlXEEodjpSKZwN3lL4vAQhoTwAiGys/wkd13NvXUQdV7YL lZjlVSAyMk+q+VNdSFmaQMiIsIZ5pl31xtrAIWaqQ9+dypTOsqxEqhaf3CxqARjR qOrJiXmeQHpSSCoQVAN6oUSEAHqyHmxOWs7cKebxFmJM96+8jTiF2SpUyJVvlqMX jgfGlnTS5h3DMFx3GStUaZezk/JaFRJmxtRdTzFj4HpL3COOjrQBmGt4X8v4OzWX 4+hFLcaLxjr3Kgnn3LEs7QM8SwzPeZechdPFBor8SxymXrJNmD0GpBBRdMqGXREI m7sC32H3wzpbuHQXIM32Is3wjehrAOn2h1cHsImGxC6qglIvIFm4BwIZ5UYPoiaK oFIEN7HsfyLPXZumMKxGd3Al8PrxXyMJZFQMfcdzI5IuPCWQGJCo6Bin+k9d5CuU fxM1SDoFx4LzphjLuTLJeD1biVKs0Wj/DaSDDcaVxhITB4inJDOMyzT3PelXipkS xveMS4G0xQNRo21SY4QpHwZhCTnKftapovmJeOH4jA2i5D4UeXdvMIAHJbp1vFqQ CZ2aA1p2Ji4RxdMOrNbGPpR8sz6A9E16PQoN7XGV3xaHcJ6Ge0kKd2EYaT4pLNxH vvLMLop0dVJuhL6h/cLj =luI1 -----END PGP SIGNATURE-----

On Thu, Oct 27, 2011 at 5:55 AM, Captain Freako
SF.hs:11:10: `>>>' is not a (visible) method of class `Arrow' Failed, modules loaded: none.
import Prelude hiding ((.),id) import Control.Category you'll also need to define `instance Category SF`, since that is a requirement for Arrows.

Thanks for the reply, David.
I tried implementing your suggestions, such that my code now looks like this:
1 -- Taken from `Programming with Arrows'.
2
3 module SF where
4
5 import Prelude hiding ((.),id)
6 import Control.Category
7 import Control.Arrow
8
9 newtype SF a b = SF {runSF :: [a] -> [b]}
10
11 instance Category SF
12
13 instance Arrow SF where
14 arr f = SF (map f)
15 SF f >>> SF g = SF (f >>> g)
but I'm getting the same error as before:
GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load SF
[1 of 1] Compiling SF ( SF.hs, interpreted )
SF.hs:15:10: `>>>' is not a (visible) method of class `Arrow'
Failed, modules loaded: none.
Any thoughts?
Thanks,
-db
On Thu, Oct 27, 2011 at 8:29 AM, David Barbour
On Thu, Oct 27, 2011 at 5:55 AM, Captain Freako
wrote: SF.hs:11:10: `>>>' is not a (visible) method of class `Arrow' Failed, modules loaded: none.
import Prelude hiding ((.),id) import Control.Category you'll also need to define `instance Category SF`, since that is a requirement for Arrows.

On Thu, Oct 27, 2011 at 7:07 PM, Captain Freako
Thanks for the reply, David. I tried implementing your suggestions, such that my code now looks like this:
While Ross Patterson followed Hughes closely, it was recognized that Category could be separated from Arrow. For `Category`, you must define (.) and id. There is a definition in the Control.Category module: (>>>) = flip (.) Thus, once you instance Category, you you get (>>>) for free. For Arrow, you must define `arr` and `first`. Regards, Dave
participants (3)
-
Captain Freako
-
David Barbour
-
Silvio Frischknecht