Skip to content

Instantly share code, notes, and snippets.

@olligobber
Created May 4, 2021 08:51
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 olligobber/7acce0d7b8d02d587f609f7e4b0689a4 to your computer and use it in GitHub Desktop.
Save olligobber/7acce0d7b8d02d587f609f7e4b0689a4 to your computer and use it in GitHub Desktop.
MWE for when AsSet breaks instances
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
import Data.Type.Set (AsSet)
class GoodType t
data Type1
data Type2
instance GoodType Type1
instance GoodType Type2
class AllGood (t :: [*])
instance AllGood '[]
instance (GoodType t, AllGood ts) => AllGood (t:ts)
-- f :: AllGood '[Type1, Type2] => Int -- works
-- f :: AllGood '[Type2, Type1] => Int -- works
-- f :: AllGood (AsSet '[Type1, Type2]) => Int -- error
-- f :: AllGood (AsSet '[Type2, Type1]) => Int -- error
-- f :: AllGood (AsSet '[Type1]) => Int -- works
-- f :: AllGood (AsSet '[Type2]) => Int -- works
f = 0
main :: IO ()
main = print f
@olligobber
Copy link
Author

Solution was to use Symbols instead of Types, and have type instance Cmp (a :: Symbol) (b :: Symbol) = CmpSymbol a b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment