Skip to content

Instantly share code, notes, and snippets.

@aavogt
Created September 11, 2015 20:23
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 aavogt/7a10024f0199dc2e8478 to your computer and use it in GitHub Desktop.
Save aavogt/7a10024f0199dc2e8478 to your computer and use it in GitHub Desktop.
injectivity problem
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeFamilies #-}
module Nikolay where
import Control.Lens
-- superclass constraint here says that TtseT is the inverse to TestT,
-- without it, the example attached to test2 fails, since otherwise we
-- could be allowed to add a
--
-- type TestT Double = Char,
--
-- and then applying test2 to a Char doesn't determine the result type
class TtseT (TestT a) ~ a => Test a where
type TestT a
myiso :: Iso' a (TestT a)
{- |
>>> test1 (120 :: Int)
'x'
-}
test1 = view myiso
{- |
>>> test2 'x'
120
-}
test2 = view (from myiso)
instance Test Int where
type TestT Int = Char
myiso = enum
type family TtseT a
type instance TtseT Char = Int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment