summaryrefslogtreecommitdiff
path: root/testsuite/tests/indexed-types/should_compile/T3484.hs
blob: 1d53b320d21908d079c3215424613c8c0b2e31f9 (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
{-# OPTIONS_GHC -Wall -fno-warn-redundant-constraints #-}
{-# LANGUAGE GADTs, RankNTypes, TypeFamilies, FlexibleContexts, ScopedTypeVariables #-}

module Absurd where

data Z = Z
newtype S n = S n
class Nat n where
   caseNat :: (n ~ Z => r) -> (forall p. (n ~ S p, Nat p) => p -> r) -> n -> r
instance Nat Z where
   caseNat _ _ = error "urk1"
instance Nat n => Nat (S n) where
   caseNat _ _ = error "urk2"

-- empty type
newtype Naught = Naught (forall a. a)
-- types are equal!
data TEq a b where
   TEq :: (a ~ b) => TEq a b

type family NatEqProves m n
type instance NatEqProves (S m) (S n) = TEq m n

noConf :: (Nat m, Nat n) => m -> TEq m n -> NatEqProves m n
noConf = undefined
predEq :: TEq (S a) (S b) -> TEq a b
predEq = undefined

data IsEq a b = Yes (TEq a b) | No (TEq a b -> Naught)

natEqDec :: forall m n. (Nat m, Nat n) => m -> n -> IsEq m n
natEqDec m n = caseNat undefined mIsS m where
    mIsS :: forall pm. (m ~ S pm, Nat pm) => pm -> IsEq m n
    mIsS pm = caseNat undefined nIsS n where
        nIsS :: forall pn. (n ~ S pn, Nat pn) => pn -> IsEq m n
        nIsS pn = case natEqDec pm pn of
            Yes TEq -> Yes TEq
            No contr -> No (contr . noConf m)
--            No contr -> No (contr . predEq)

-- strange things:
-- (1) commenting out the "Yes" case or changing it to "undefined" makes compilation succeed
-- (2) replacing the "No" line with with the commented out "No" line makes compilation succeed