Commit f6358462 authored by Iavor S. Diatchki's avatar Iavor S. Diatchki

Merge remote-tracking branch 'origin/type-nats'

parents 17e45d20 b473b251
-- Test Trac #2766
:set -XTypeOperators
:m Control.Arrow
:t first :: Arrow (~>) => b~>c -> (b, d)~>(c, d)
:t first :: Arrow to => b `to` c -> (b, d) `to` (c, d)
type a ~> b = a -> b
:t first :: b~>c -> (b, d)~>(c, d)
first :: Arrow (~>) => b~>c -> (b, d)~>(c, d)
:: Arrow (~>) => (~>) b c -> (~>) (b, d) (c, d)
first :: Arrow to => b `to` c -> (b, d) `to` (c, d)
:: Arrow to => to b c -> to (b, d) (c, d)
first :: b~>c -> (b, d)~>(c, d) :: (b ~> c) -> (b, d) ~> (c, d)
module ShouldCompile where
data a <--> b = Mk a b
test :: [a] -- ^ doc1
-> a <--> b
-> [a] -- ^ blabla
......
==================== Parser ====================
module ShouldCompile where
data <--> a b = Mk a b
test ::
[a] <document comment> -> (a <--> (b -> [a])) <document comment>
test xs ys = xs
......
module ShouldCompile where
data a <--> b = Mk a b
test :: [a] -- ^ doc1
-> a <--> b
-> [a] -- ^ doc3
......
mod89.hs:3:19: parse error on input `('
mod89.hs:3:16: Module `Prelude' does not export `map(..)'
......@@ -18,9 +18,9 @@ import Data.Monoid (Monoid(..))
-- First we define the type class Monoidy:
class Monoidy (~>) comp id m | m (~>) comp id where
munit :: id ~> m
mjoin :: m `comp` m ~> m
class Monoidy to comp id m | m to comp id where
munit :: id `to` m
mjoin :: (m `comp` m) `to` m
-- We use functional dependencies to help the typechecker understand that
-- m and ~> uniquely determine comp (times) and id.
......
......@@ -17,11 +17,11 @@ import Data.Monoid (Monoid(..))
-- First we define the type class Monoidy:
class Monoidy ((~>) :: k0 -> k1 -> *) (m :: k1) where
type MComp (~>) m :: k1 -> k1 -> k0
type MId (~>) m :: k0
munit :: MId (~>) m ~> m
mjoin :: MComp (~>) m m m ~> m
class Monoidy (to :: k0 -> k1 -> *) (m :: k1) where
type MComp to m :: k1 -> k1 -> k0
type MId to m :: k0
munit :: MId to m `to` m
mjoin :: MComp to m m m `to` m
-- We use functional dependencies to help the typechecker understand that
-- m and ~> uniquely determine comp (times) and id.
......
......@@ -352,6 +352,7 @@ test('tc257', normal, compile, [''])
test('tc258', normal, compile, [''])
test('tc259', normal, compile, [''])
test('tc260', normal, compile, [''])
test('tc261', normal, compile, [''])
test('GivenOverlapping', normal, compile, [''])
test('SilentParametersOverlapping', normal, compile, [''])
......
......@@ -15,7 +15,7 @@ import Control.Arrow
-- comp1 :: Arrow (-=>) => b-=>c -> c-=>d -> b-=>d
comp1 :: Arrow (~>) => b~>c -> c~>d -> b~>d
comp1 :: Arrow to => b `to` c -> c `to` d -> b `to` d
comp1 f g = proc x -> do
b <- f -< x
g -< b
......@@ -23,26 +23,26 @@ comp1 f g = proc x -> do
-- arrowp produces
-- comp1 f g = (f >>> g)
comp :: Arrow (~>) => (b~>c, c~>d)~>(b~>d)
comp :: Arrow to => (b `to` c, c `to` d) `to` (b `to` d)
comp = arr (uncurry (>>>))
-- app :: Arrow to => (b c, b) `to` c
type R = Float
type I = Int
z1,z2 :: Arrow to => I `to` (R `to` R)
z1 = undefined
z2 = z1
z3 :: Arrow to => (I,I) `to` (R `to` R,R `to` R)
z3 = z1 *** z2
z4 :: Arrow to => (I,I) `to` (R `to` R)
z4 = z3 >>> comp
comp4,comp5 :: Arrow (~>) =>
comp4,comp5 :: Arrow to =>
b `to` (c `to` d) -> e `to` (d `to` f) -> (b,e) `to` (c `to` f)
comp4 g f = proc (b,e) -> do
g' <- g -< b
......@@ -51,7 +51,7 @@ comp4 g f = proc (b,e) -> do
comp5 g f = (g *** f) >>> comp
lam,lam2 :: Arrow (~>) => (e,b)~>c -> e~>(b~>c)
lam,lam2 :: Arrow to => (e,b) `to` c -> e `to` (b `to` c)
lam f = arr $ \ e -> arr (pair e) >>> f
......@@ -65,7 +65,7 @@ lam2 f = proc e ->
returnA -< c)
-- I desugared with the arrows preprocessor, removed extra parens and
-- renamed "arr" (~>) "pure", (~>) get
-- renamed "arr" to "pure", to get
--
-- lam f = pure (\ e -> pure (\ b -> (e, b)) >>> f)
......@@ -85,27 +85,27 @@ curry4 f = \ e -> f . (pair e)
comp6 :: Arrow (~>) => b~>(c~>d) -> e~>(d~>f)
-> b~>(e~>(c~>f))
comp6 :: Arrow to => b `to` (c `to` d) -> e `to` (d `to` f)
-> b `to` (e `to` (c `to` f))
comp6 g f = lam $ comp5 g f
-- What about uncurrying?
-- uncurryA :: Arrow (~>) => b~>(c~>d)
-- -> (b,c)~>d
-- uncurryA :: Arrow to => b `to` (c `to` d)
-- -> (b,c) `to` d
-- uncurryA f = proc (b,c) -> do
-- f' <- f -< b
-- returnA -< f' c
-- Why "lam" instead of "curryA" (good name also): so I can use Arrows
-- lambda notation, similar (~>)
-- lambda notation, similar to
compF g f = \ b e -> g b . f e
-- But I haven't figured out how (~>).
-- But I haven't figured out how to.
-- comp7 :: Arrow (~>) => b~>(c~>d) -> e~>(d~>f)
-- -> b~>(e~>(c~>f))
-- comp7 :: Arrow to => b `to` (c `to` d) -> e `to` (d `to` f)
-- -> b `to` (e `to` (c `to` f))
-- comp7 g f = proc b -> proc e -> do
-- g' <- g -< b
-- f' <- f -< e
......@@ -117,29 +117,29 @@ compF g f = \ b e -> g b . f e
-- (| lam (\ b -> undefined) |)
-- Oh! The arrow syntax allows bindings with *infix* operators. And I
-- don't know how (~>) finish comp7.
-- don't know how to finish comp7.
-- Uncurried forms:
comp8 :: Arrow (~>) => (b,c)~>d -> (e,d)~>k -> (b,c,e)~>k
comp8 :: Arrow to => (b,c) `to` d -> (e,d) `to` k -> (b,c,e) `to` k
comp8 g f = proc (b,c,e) -> do
d <- g -< (b,c)
f -< (e,d)
-- This looks like straightforward~>translation. With insertions of
-- curry & uncurry operators, it'd probably be easy (~>) handle curried
-- This looks like straightforward `to` translation. With insertions of
-- curry & uncurry operators, it'd probably be easy to handle curried
-- definitions as well.
-- Simpler example, for experimentation
comp9 :: Arrow (~>) => (c,d)~>e -> b~>d -> (b,c)~>e
comp9 :: Arrow to => (c,d) `to` e -> b `to` d -> (b,c) `to` e
comp9 g f = proc (b,c) -> do
d <- f -< b
g -< (c,d)
-- Desugared:
comp9' :: Arrow (~>) => (c,d)~>e -> b~>d -> (b,c)~>e
comp9' :: Arrow to => (c,d) `to` e -> b `to` d -> (b,c) `to` e
comp9' g f = first f >>> arr (\ (d,c) -> (c,d)) >>> g
{-# LANGUAGE TypeOperators #-}
module TcOK where
newtype (f <.> g) a = Compose (f (g a))
tcfail094.hs:7:14: parse error on input `1'
tcfail094.hs:7:14:
Illegal literal in type (use -XDataKinds to enable): 1
tcfail173.hs:5:10:
Malformed head of type or class declaration: (f <.> g) a
tcfail173.hs:5:12:
Illegal declaration of a type or class operator `<.>'
Use -XTypeOperators to declare operators in type and declarations
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment