Created
September 11, 2015 20:23
-
-
Save aavogt/7a10024f0199dc2e8478 to your computer and use it in GitHub Desktop.
injectivity problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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