Created
November 18, 2020 18:19
-
-
Save ChrisPenner/cef35c3b8db9b945084c30ade437e337 to your computer and use it in GitHub Desktop.
A hack to require type applications, even when not necessary
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 ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE AllowAmbiguousTypes #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
-- Don't export this, it's just to make it so the type family *could* have a different | |
-- result, even though it never will! | |
data Never | |
type family Identity a where | |
Identity Never = () | |
Identity a = a | |
-- Set up the instance | |
class From a b where | |
from :: a -> b | |
instance From a [a] where | |
from = pure | |
-- The type fam makes (Identity b) ambigous until applied, even though `Identity b ~ b` always. | |
into :: forall b a. (From a (Identity b)) => a -> Identity b | |
into = from | |
-- This expression fails to compile without the type application | |
use :: String | |
use = into @String 'a' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment