Skip to content

Instantly share code, notes, and snippets.

@Gurkenglas
Last active February 9, 2022 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gurkenglas/137914f5790f0e0390c631f9678832da to your computer and use it in GitHub Desktop.
Save Gurkenglas/137914f5790f0e0390c631f9678832da to your computer and use it in GitHub Desktop.
forallgadts
{-# LANGUAGE GADTs, RankNTypes #-}
data Foo a where
Bar :: Int -> Foo Int
Baz :: String -> Foo String
newtype Foo2 a = Foo2 {runFoo2 :: forall f. (Int -> f Int) -> (String -> f String) -> f a}
foo2s :: Foo2 String
foo2s = Foo2 $ \bar baz -> baz "asd"
{-# LANGUAGE RankNTypes #-}
newtype Stream a = Stream {runStream :: forall f. (a -> f a -> f a) -> f a}
fromn :: Int -> Stream Int
fromn n = Stream $ \c -> c n $ runStream (fromn (n+1)) c
tolist :: Stream a -> [a]
tolist s = runStream s (:)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment