summaryrefslogtreecommitdiff
path: root/tests/examples/Arrow2.hs
blob: b6e71704a841d1f0bbc1c6db83381ea368704524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{-# LANGUAGE Arrows #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UnicodeSyntax #-}
module Arrow2 where

nonUnicode :: forall a . a -> IO Int
nonUnicode _ = do
  x <- readChar
  return 4

-- ^ An opaque ESD handle for recording data from the soundcard via ESD.
data Recorder fr ch (r ∷ * -> *)
    = Recorder {
        reCloseH :: !(FinalizerHandle r)
      }

f :: Arrow a => a (Int,Int,Int) Int
f = proc (x,y,z) -> returnA -< x+y

f2 :: Arrow a => a (Int,Int,Int) Int
f2 = proc (x,y,z) -> returnA >- x+y

g :: ArrowApply a => Int -> a (a Int Int,Int) Int
g y = proc (x,z) -> x -<< 2+y

g2 :: ArrowApply a => Int -> a (a Int Int,Int) Int
g2 y = proc (x,z) -> x >>- 2+y

-- -------------------------------------

unicode ∷ ∀ a . a → IO Int
unicode _ = do
  x ← readChar
  return 4

-- ^ An opaque ESD handle for recording data from the soundcard via ESD.
-- data RecorderU fr ch (r ∷ ★ → ★)
data RecorderU fr ch (r ∷ * → *)
    = RecorderU {
        reCloseHU ∷ !(FinalizerHandle r)
      }

fU :: Arrow a  ⇒ a (Int,Int,Int) Int
fU = proc (x,y,z) -> returnA ⤙ x+y

f2U :: Arrow a ⇒ a (Int,Int,Int) Int
f2U = proc (x,y,z) -> returnA ⤚ x+y

gU :: ArrowApply a ⇒ Int -> a (a Int Int,Int) Int
gU y = proc (x,z) -> x ⤛ 2+y

g2U :: ArrowApply a ⇒ Int -> a (a Int Int,Int) Int
g2U y = proc (x,z) -> x ⤜ 2+y