-
-
Save gwils/a5ad80d61b3e7868406bb463e5cd0d85 to your computer and use it in GitHub Desktop.
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 FlexibleInstances #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
import Control.Lens | |
import Data.Foldable | |
newtype JWKSet = JWKSet [JWK] | |
data JWK = JWK | |
deriving Show | |
class JWKStore a where | |
keys :: Fold a JWK | |
instance Foldable t => JWKStore (t JWK) where | |
keys = folding id | |
instance JWKStore JWKSet where | |
keys = folding (\(JWKSet xs) -> xs) | |
data ContrivedJWKThingo a = ContrivedJWKThingo [JWK] [a] deriving Foldable | |
instance JWKStore (ContrivedJWKThingo a) where | |
keys = folding (\(ContrivedJWKThingo js _) -> js) | |
v :: ContrivedJWKThingo JWK | |
v = ContrivedJWKThingo [JWK, JWK] [JWK, JWK, JWK] | |
-- what code goes here to screw up? | |
---- | |
class GetKeys a where | |
getKeys :: a -> [Char] | |
instance Foldable t => GetKeys (t Char) where | |
getKeys = toList | |
data HasInts a = HasInts [Char] [a] deriving Foldable | |
instance GetKeys (HasInts a) where | |
getKeys (HasInts is _) = is | |
e :: HasInts Char | |
e = HasInts ['a', 'b', 'c'] ['d', 'e', 'f'] | |
r = getKeys (HasInts ['a', 'b', 'c'] ['d', 'e', 'f']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment