summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/T12734a.hs
blob: 5f1da8b81856b6f733378506e852530c231eeb6b (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE UndecidableInstances      #-}
{-# LANGUAGE GADTs                     #-}
{-# LANGUAGE PolyKinds                 #-}
{-# LANGUAGE TypeApplications          #-}


-- This version is shorter than T12734, and should yield a
-- type error message.  If things go wrong, you get
-- an infinite loop

module T12734a where

import Prelude
import Data.Kind
import Control.Applicative
import Control.Monad.Fix
import Control.Monad.Trans.Identity
import Control.Monad.Trans.Class
import Control.Monad.IO.Class


data A
data B
data Net
data Ty

data Layer4 t l
data TermStore

data Stack lrs (t :: Type -> Type) where
    SLayer :: t l -> Stack ls t -> Stack (l ': ls) t
    SNull  :: Stack '[] t

instance ( Con m (t l)
         , Con m (Stack ls t)) => Con m (Stack (l ': ls) t)
instance Monad m               => Con m (Stack '[]       t)
instance ( expr ~ Expr t lrs
         , Con m (TStk t lrs)) => Con m (Layer4 expr Ty)


newtype Expr  t lrs    = Expr (TStk t lrs)
type TStk t lrs = Stack lrs (Layer4 (Expr t lrs))


class Con m t


-- HERE IS A FUNNY BEHAVIOR: the commented line raises context reduction stack overflow
test_gr :: forall m t lrs bind.
           ( Con m (TStk t lrs)
            , bind ~ Expr t lrs
--        ) => m (Expr t lrs)       -- GHC 8 worked if you said this...
          ) => m bind               -- but not this!
test_gr = undefined


newtype KT (cls :: Type) (t :: k) (m :: Type -> Type) (a :: Type)
   = KT (IdentityT m a)

test_ghc_err :: KT A '[Ty] IO (Expr Net '[Ty])

test_ghc_err = test_gr @(KT A '[Ty] IO) @_ @'[Ty] @(Expr Net '[Ty])

{-  Works!
test_ghc_err = test_gr @(KT A '[Ty] IO)
                       @Net
                       @'[Ty]
                       @(Expr Net '[Ty])
-}

{-  Some notes.  See comment:10 on Trac #12734

[W] Con m (TStk t lrs)
[W] Inferable A lrs m
[W] bind ~ Expr t lrs
[W] m bind ~ KT A '[Ty] IO (Expr Net '[Ty])

==> m := KT A '[Ty] IO
    bind := Expr Net '[Ty]
    t := Net
    lrs := '[Ty]

[W] Con m (TStk t lrs)
  = Con m (Stack lrs (Layer4 bind))
--> inline lrs
[W] Con m (Stack '[Ty] (Layer4 bind))
--> instance
[W] Con m (Stack '[] bind)
    --> Monad m
+
[W] Con m (Layer4 bind Ty)
-->
[W] bind ~ Expr t0 lrs0
[W] Con m (TStk t0 lrs0)
-}