Skip to content

Instantly share code, notes, and snippets.

@cdparks
Created September 7, 2017 00:50
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 cdparks/a80972481b28af99775adc15a492391e to your computer and use it in GitHub Desktop.
Save cdparks/a80972481b28af99775adc15a492391e to your computer and use it in GitHub Desktop.
Attempting to recreate https://twitter.com/CodaFi_/status/905583919550132226 in Haskell without unsafeCoerce
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Typeable
import Control.Monad
import Control.Exception
import Prelude hiding (id)
-- Is it possible to do something like this without Typeable?
id :: forall a. Typeable a => a -> a
id x =
case eqT of
Just (Refl :: a :~: Int) -> 5
Nothing -> x
expect :: Bool -> IO ()
expect cond = void (evaluate (assert cond ()))
main :: IO ()
main = do
expect $ id True == True
expect $ id @Int 1 == 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment