Beginners arrow question

I'm using arrows for the first time, with HXT. I think I'm getting the hang of it, but one problem has me stumped. I have a function "lookupFormatter" which takes a string and returns an arrow, and I want to use that arrow. Something like this: myProblem :: (ArrowXml a) -> a XmlTree String myProblem = proc xml do name <- getAttrValue "name" -< xml fmt <- arr lookupFormatter -< name fmt -< xml But I can't figure out how to do it. I get "fmt: not in scope". Can anyone help? Thanks, Paul.

You can't use variables introduced in "proc" anywhere except on the right side of "-<". OK, you actually can do this, but your arrow should be an instance of ArrowApply (which means that you don't really need it at all, since all such arrows are in fact monads). Your "myProblem" is desugared as something like arr (\xml -> (xml,xml)) >>> second (getAttrValue "name") >>> second (arr (\name -> (name,name))) >>> second (second (arr lookupFormatter))
arr (\(xml,(name,fmt)) -> xml) >>> fmt
On 5 Apr 2008, at 22:05, Paul Johnson wrote:
I'm using arrows for the first time, with HXT. I think I'm getting the hang of it, but one problem has me stumped. I have a function "lookupFormatter" which takes a string and returns an arrow, and I want to use that arrow. Something like this:
myProblem :: (ArrowXml a) -> a XmlTree String myProblem = proc xml do name <- getAttrValue "name" -< xml fmt <- arr lookupFormatter -< name fmt -< xml
But I can't figure out how to do it. I get "fmt: not in scope".
Can anyone help?
Thanks,
Paul.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Paul Johnson wrote:
I'm using arrows for the first time, with HXT. I think I'm getting the hang of it, but one problem has me stumped. I have a function "lookupFormatter" which takes a string and returns an arrow, and I want to use that arrow. Something like this:
myProblem :: (ArrowXml a) -> a XmlTree String myProblem = proc xml do name <- getAttrValue "name" -< xml fmt <- arr lookupFormatter -< name fmt -< xml
But I can't figure out how to do it. I get "fmt: not in scope".
ArrowApply is one way, if there is an instance for it: module Main where import Control.Arrow adder :: (Arrow a) => Int -> a Int Int adder i = arr (i+) adderUser :: (ArrowApply a, Arrow a) => a Int Int adderUser = proc x -> do a <- arr adder -< x y <- app -< (a,x) returnA -< y main = mapM_ (print . (adderUser :: (->) Int Int)) [1..10] Claude -- http://claudiusmaximus.goto10.org

On 05/04/2008, Paul Johnson
myProblem :: (ArrowXml a) -> a XmlTree String myProblem = proc xml do name <- getAttrValue "name" -< xml fmt <- arr lookupFormatter -< name fmt -< xml
GHC has a special syntax for using ArrowApply (which HXT is an instance of). Whenever the expression to the left of -< needs to involve a local variable, you can replace -< with -<< and it should work. To understand better what it means, you can read http://www.haskell.org/ghc/docs/latest/html/users_guide/arrow-notation.html -- it's basically just a shorthand for using 'app'.
myProblem :: (ArrowXml a) -> a XmlTree String myProblem = proc xml do name <- getAttrValue "name" -< xml fmt <- arr lookupFormatter -< name fmt -<< xml
Try that and see how it goes. - Cale

On Sat, Apr 5, 2008 at 4:00 PM, Cale Gibbard
GHC has a special syntax for using ArrowApply (which HXT is an instance of). Whenever the expression to the left of -< needs to involve a local variable, you can replace -< with -<< and it should work. To understand better what it means, you can read http://www.haskell.org/ghc/docs/latest/html/users_guide/arrow-notation.html
Sweet! I didn't know that; I knew that ArrowApply gave you the ability to use bindings in the arrows, but it always bugged me that I couldn't even when I did have an instance. Go GHC! :-) Luke
participants (5)
-
Cale Gibbard
-
Claude Heiland-Allen
-
Luke Palmer
-
Miguel Mitrofanov
-
Paul Johnson