Skip to content

Instantly share code, notes, and snippets.

@schar
Created December 12, 2021 03:20
Show Gist options
  • Save schar/8201b20d6770f9e6a41b18476c3ea22e to your computer and use it in GitHub Desktop.
Save schar/8201b20d6770f9e6a41b18476c3ea22e to your computer and use it in GitHub Desktop.
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
data Ex = forall a. Ex a
type State i o a = i -> (a, o)
-- enforce independence of types i and a:
newtype Filt a = Filt { unFilt :: forall i. i -> (a, Ex) }
-- generate a copy to subject to Filt
dup :: State i o a -> (State i o a, State i Ex a)
dup m = (m, \i -> let (x, j) = m i in (x, Ex j))
x :: State i i ()
x = \i -> ((), i)
test1 :: State i i ()
test1 = let (a, b) = dup x
_ = Filt b
in a
y :: State i () i
y = \i -> (i, ())
--test2 = let (a, b) = dup y
-- _ = Filt b
-- in a
-- => rigid type variable error
-- but seems it's impossible to get the relevant pattern into a function
-- test m = let (a, b) = dup m
-- _ = Filt b
-- in a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment