[Haskell-cafe] is this an arrow?

2012-04-13 Thread Johannes Waldmann
Dear Cafe, I have the following types:

type Computer a b =  ( a - IO ( Maybe b ) )
type Transformer a b c d =  Computer a ( b, c - d )

For example, a SAT solver:
minisat :: Computer CNF Assignment,

and when I use it to solve an application problem
via transformation to SAT, I need
t :: Transformer Problem SAT Assignment Solution

Now - what is the proper abstraction? Is this an arrow somehow?
And is there already a type and a library that would
contain useful combinators like some of these:

http://autolat.imn.htwk-leipzig.de/gitweb/?p=box;a=blob;f=src/exotic/Strategy.hs;h=238b5f55fabf356e0ce484d0f6b882a06d6e6cfc;hb=HEAD

Thanks - J.W.



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] is this an arrow?

2012-04-13 Thread Daniel Peebles
On Fri, Apr 13, 2012 at 7:49 AM, Johannes Waldmann 
waldm...@imn.htwk-leipzig.de wrote:

 type Computer a b =  ( a - IO ( Maybe b ) )
 type Transformer a b c d =  Computer a ( b, c - d )


Computer looks like Kleisli (MaybeT IO), which would be a valid instance of
Arrow.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Trouble defining `instance Arrow SF'

2011-10-27 Thread Captain Freako
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

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble defining `instance Arrow SF'

2011-10-27 Thread Silvio Frischknecht
-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-

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble defining `instance Arrow SF'

2011-10-27 Thread David Barbour
On Thu, Oct 27, 2011 at 5:55 AM, Captain Freako capn.fre...@gmail.comwrote:

 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.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble defining `instance Arrow SF'

2011-10-27 Thread Captain Freako
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 dmbarb...@gmail.com wrote:

 On Thu, Oct 27, 2011 at 5:55 AM, Captain Freako capn.fre...@gmail.com
 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.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble defining `instance Arrow SF'

2011-10-27 Thread David Barbour
On Thu, Oct 27, 2011 at 7:07 PM, Captain Freako capn.fre...@gmail.comwrote:

 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
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proposal: Subcomputations in arrow notation

2011-09-22 Thread Ertugrul Soeylemez
Paterson, Ross r.pater...@city.ac.uk wrote:

 See the GHC Arrow notation documentation for more about the banana
 brackets, which let you use user-defined control structures like
 event.

I have reread the documentation now.  It seems that there are a lot of
syntactic constructs, which I've missed.  Particularly the banana
bracket notation does exactly what I want.  Thanks a lot!


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://ertes.de/



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Proposal: Subcomputations in arrow notation

2011-09-21 Thread Ertugrul Soeylemez
Hello fellow Haskellers,

this is a proposal to extend the arrow notation (-XArrows).  I find
myself writing the following very often:

system :: Wire IO () String
system =
proc _ - do
botAddPeriod - succ ^ noise - ()
botAddSpeed - noise1 - ()
botAddStart - noise1 - ()
botMsg - event addBot - (botAddPeriod, botAddSpeed, botAddStart)

bots - manager - ((), maybe MgrNop id botMsg)
let botStr = concatMap (printf %8.2) . M.elems $ bots :: String
identity - printf Bot positions: %s botStr

where
addBot :: Wire IO (Double, Double, Double) (MgrMsg Int IO () Double)
addBot =
proc (addPeriod, addSpeed, addStart) - do
periodically - addPeriod
botId - identifier - ()
identity - MgrAdd botId (constant addSpeed  integral 
addStart)

The relevant part is the first paragraph of the first arrow computation:

botAddPeriod - succ ^ noise - ()
botAddSpeed - noise1 - ()
botAddStart - noise1 - ()
botMsg - event addBot - (botAddPeriod, botAddSpeed, botAddStart)

This line should generate a message for the bot manager at random
intervals.  The actual event generator is in the second arrow
computation 'addBot'.  I would like to be able to write this more in
line with the rest of the code.  The following is possible:

system :: Wire IO () String
system =
proc _ - do
botAddPeriod - succ ^ noise - ()
botAddSpeed - noise1 - ()
botAddStart - noise1 - ()

botMsg - event (proc (addPeriod, addSpeed, addStart) - do
periodically - addPeriod
botId - identifier - ()
identity - MgrAdd botId (constant addSpeed  integral 
addStart))
- (botAddPeriod, botAddSpeed, botAddStart)

bots - manager - ((), maybe MgrNop id botMsg)
let botStr = concatMap (printf %8.2) . M.elems $ bots :: String
identity - printf Bot positions: %s botStr

This is probably not a big improvement.  It's more concise, but also
harder to understand.  My proposal is to add syntax to allow the
following notation:

system :: Wire IO () String
system =
proc _ - do
botAddPeriod - succ ^ noise - ()
botAddSpeed - noise1 - ()
botAddStart - noise1 - ()

botMsg - event $ do
periodically - addPeriod
botId - identifier - ()
identity - MgrAdd botId (constant addSpeed  integral 
addStart)

bots - manager - ((), maybe MgrNop id botMsg)
let botStr = concatMap (printf %8.2) . M.elems $ bots :: String
identity - printf Bot positions: %s botStr

Again the relevant part is the event generator in the middle.  In this
hypothetical syntax, the compiler would figure out from the inner
computation, which variables from the outer scope are used and pass them
automatically in an appropriate tuple.  You wouldn't need any explicit
passing anymore.

If others like the idea, too, and there is nobody to implement it, then
I would be willing to get in touch with the GHC code and implement this
as a patch myself.

What do you think?


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://ertes.de/



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proposal: Subcomputations in arrow notation

2011-09-21 Thread Jake McArthur
I think this proposal makes so much sense that I'm surprised it didn't
already work this way.

- Jake

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proposal: Subcomputations in arrow notation

2011-09-21 Thread Paterson, Ross
Ertugrul Soeylemez writes:
  I find myself writing the following very often:

 system :: Wire IO () String
 system =
 proc _ - do
 botAddPeriod - succ ^ noise - ()
 botAddSpeed - noise1 - ()
 botAddStart - noise1 - ()
 botMsg - event addBot - (botAddPeriod, botAddSpeed, botAddStart)

 bots - manager - ((), maybe MgrNop id botMsg)
 let botStr = concatMap (printf %8.2) . M.elems $ bots :: String
 identity - printf Bot positions: %s botStr

 where
 addBot :: Wire IO (Double, Double, Double) (MgrMsg Int IO () Double)
 addBot =
 proc (addPeriod, addSpeed, addStart) - do
 periodically - addPeriod
 botId - identifier - ()
 identity - MgrAdd botId (constant addSpeed  integral 
 addStart)

If addPeriod is supposed to be the same as botAddPeriod, etc, this should be
equivalent:

system :: Wire IO () String
system =
proc _ - do
addPeriod - succ ^ noise - ()
addSpeed - noise1 - () 
addStart - noise1 - () 
botMsg - (|event (do
periodically - addPeriod
botId - identifier - ()
identity - MgrAdd botId (constant addSpeed  integral 
addStart))|)

bots - manager - ((), maybe MgrNop id botMsg)
let botStr = concatMap (printf %8.2) . M.elems $ bots :: String
identity - printf Bot positions: %s botStr

See the GHC Arrow notation documentation for more about the banana brackets,
which let you use user-defined control structures like event.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Weird behavior with arrow commands

2010-07-24 Thread Jürgen Doser
El vie, 23-07-2010 a las 23:27 -0400, Ronald Guida escribió:
 I am trying to figure out how to use GHC's arrow commands, and I found
 some extremely weird behavior.

CC'ed to ghc-users, because this may be a ghc bug.

 In GHC's manual, there is a description of arrow commands, which I
 don't really understand.
 http://www.haskell.org/ghc/docs/latest/html/users_guide/arrow-notation.html#id667303
 (Primitive Constructs)
 
 I have two questions:
 1. What are arrow commands supposed to do?
 2. What is this code supposed to do?
 
 -- start of code --
 
 {-# LANGUAGE Arrows #-}
 module Main where
 
 import Control.Arrow
 
 foo :: (b - String) - b, Int), Float), Double) - String) - (b - 
 String)
 foo f g b = f b ++   ++ g (((b, 8), 1.0), 6.0)
 
 bar :: (t - String) - ((Double, Int) - String) - t - String
 bar f g  = proc x - do
   (f - x) `foo` \n m - g - (n)
 
 main = do
   putStrLn $ foo show show 17
   putStrLn $ bar show show 17
   putStrLn $ foo show show 42
   putStrLn $ bar show show 42
 
 -- end of code --
 
 Output from GHCi:
 
 17 (((17,8),1.0),6.0)
 17 (6.730326920298707e-306,0)
 42 (((42,8),1.0),6.0)
 42 (6.730326920298707e-306,0)
 
 Output after compiling with GHC:
 
 17 (((17,8),1.0),6.0)
 17 (5.858736684536801e-270,0)
 42 (((42,8),1.0),6.0)
 42 (5.858736684536801e-270,0)
 
 GHC Version:
 The Glorious Glasgow Haskell Compilation System, version 6.12.3


This seems to be a bug in ghc. First, let's fix bar to give the full
three arguments (Int, Float, Double)  to g:

bar f g  = proc x - do
  (f - x) `foo` (\n m k - g - (n,m,k))

ghc infers the type:

bar :: (t - String) - ((Double, Float, Int) - String) - t - String

and we see that the argument order in the second argument to bar is
reversed. But the arguments are still given to bar in the order (Int,
Float, Double). For example, the 6.0 in foo is interpreted as an Int and
outputs a 0 (the first 32 bits in such a small double are zeros).
When one varies the numbers in foo, one can see the effects in bar. Can
someone from GHC HQ confirm my understanding, or is this just not
supposed to work with multiple arguments?

Jürgen


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Weird behavior with arrow commands

2010-07-24 Thread Ross Paterson
On Sat, Jul 24, 2010 at 01:10:56PM +0200, Jürgen Doser wrote:
 This seems to be a bug in ghc. First, let's fix bar to give the full
 three arguments (Int, Float, Double)  to g:
 
 bar f g  = proc x - do
   (f - x) `foo` (\n m k - g - (n,m,k))
 
 ghc infers the type:
 
 bar :: (t - String) - ((Double, Float, Int) - String) - t - String
 
 and we see that the argument order in the second argument to bar is
 reversed. But the arguments are still given to bar in the order (Int,
 Float, Double). For example, the 6.0 in foo is interpreted as an Int and
 outputs a 0 (the first 32 bits in such a small double are zeros).
 When one varies the numbers in foo, one can see the effects in bar. Can
 someone from GHC HQ confirm my understanding, or is this just not
 supposed to work with multiple arguments?

You're right: it's getting the argument order wrong, so -dcore-lint
fails on this example and all bets are off.  Definitely a bug.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Weird behavior with arrow commands

2010-07-23 Thread Ronald Guida
I am trying to figure out how to use GHC's arrow commands, and I found
some extremely weird behavior.

In GHC's manual, there is a description of arrow commands, which I
don't really understand.
http://www.haskell.org/ghc/docs/latest/html/users_guide/arrow-notation.html#id667303
(Primitive Constructs)

I have two questions:
1. What are arrow commands supposed to do?
2. What is this code supposed to do?

-- start of code --

{-# LANGUAGE Arrows #-}
module Main where

import Control.Arrow

foo :: (b - String) - b, Int), Float), Double) - String) - (b - String)
foo f g b = f b ++   ++ g (((b, 8), 1.0), 6.0)

bar :: (t - String) - ((Double, Int) - String) - t - String
bar f g  = proc x - do
  (f - x) `foo` \n m - g - (n)

main = do
  putStrLn $ foo show show 17
  putStrLn $ bar show show 17
  putStrLn $ foo show show 42
  putStrLn $ bar show show 42

-- end of code --

Output from GHCi:

17 (((17,8),1.0),6.0)
17 (6.730326920298707e-306,0)
42 (((42,8),1.0),6.0)
42 (6.730326920298707e-306,0)

Output after compiling with GHC:

17 (((17,8),1.0),6.0)
17 (5.858736684536801e-270,0)
42 (((42,8),1.0),6.0)
42 (5.858736684536801e-270,0)

GHC Version:
The Glorious Glasgow Haskell Compilation System, version 6.12.3

Thank you
-- Ron
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ArrowChoice for simulation arrow (Sim)

2008-02-28 Thread Steve Lihn
Hi,
In John Hughes\' paper \Programming with arrows\ [1] Section 5, the
simulation arrow is defined (Sim). All the examples went well.
However, when I want to use it beyond circuit simulation and I added a
\if-then-else\ line, GHC is asking to define ArrowChoice for Sim.

Does anybody have the ArrowChoice definition for Sim ?

Thanks,
Steve

[1] http://www.cs.chalmers.se/~rjmh/afp-arrows.pdf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe