/
Lib.hs
54 lines (39 loc) · 1.59 KB
/
Lib.hs
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
{-# language RankNTypes, TypeFamilies, KindSignatures, MultiParamTypeClasses, DataKinds, ConstraintKinds, ImplicitParams, UndecidableInstances, FlexibleContexts, FlexibleInstances #-}
{-# OPTIONS_GHC -Wno-orphans -Wno-missing-methods #-}
module Lib where
import Data.Kind
import GHC.Stack (HasCallStack)
import GHC.Classes (IP(..))
import GHC.TypeLits (TypeError, ErrorMessage(..))
-- The Problem:
--
-- GHC complains about `bar` with the `TypeError` in the `instance IP
-- "provideCallStack" ProvideCallStack`.
--
-- Removing the type error allows the program to compile without error.
--
-- Adding a type signature to `bar` that specifies `RequireCallStack` also
-- fixes the issue.
someFunc :: RequireCallStack => IO ()
someFunc = do
errorRequireCallStack "asdf"
let bar = errorRequireCallStack "qwer"
bar
alsoWeird :: IO ()
alsoWeird = provideCallStack $ do
-- `RequireCallStack` should be a satisfied constraint here, as
-- evidenced by this building:
someFunc
-- But we get an error in this let binding.
let bar = errorRequireCallStack "qwer"
bar
errorRequireCallStack :: RequireCallStack => String -> x
errorRequireCallStack = error
instance TypeError ('Text "Add RequireCallStack to your function context or use provideCallStack") => IP "provideCallStack" ProvideCallStack
type RequireCallStack = (HasCallStack, RequireCallStackImpl)
type RequireCallStackImpl = ?provideCallStack :: ProvideCallStack
data ProvideCallStack = ProvideCallStack
provideCallStack :: (RequireCallStackImpl => r) -> r
provideCallStack r = r
where
?provideCallStack = ProvideCallStack