Skip to content

Instantly share code, notes, and snippets.

@neongreen
Created June 7, 2019 10:42
Show Gist options
  • Save neongreen/fc76ef1dcfe8f6fd0d911f77773d96aa to your computer and use it in GitHub Desktop.
Save neongreen/fc76ef1dcfe8f6fd0d911f77773d96aa to your computer and use it in GitHub Desktop.
{-# 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