Created
June 7, 2019 10:42
-
-
Save neongreen/fc76ef1dcfe8f6fd0d911f77773d96aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 RankNTypes #-} | |
{-# LANGUAGE AllowAmbiguousTypes #-} | |
{-# LANGUAGE TypeApplications #-} | |
class Voodoo tag where | |
-- Let's define an operation that requires TypeApplications in order to work | |
voodoo :: Int -> String | |
-- Let's also have an instance (we could have more, of course) | |
data Tag | |
instance Voodoo Tag where | |
voodoo = show | |
-- Now, this works: | |
-- | |
test1 = voodoo @Tag 3 | |
-- But this doesn't: | |
-- | |
-- test2 = voodoo 3 @Tag | |
-- | |
-- • Cannot apply expression of type ‘String’ | |
-- to a visible type argument ‘Tag’ | |
-- Can we define voodoo' that will work? (Using obnoxious amounts of black | |
-- magic, if necessary) | |
voodoo' :: Int -> (forall tag. Voodoo tag => String) | |
voodoo' = undefined | |
test3 = voodoo' 3 @Tag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment