Skip to content

Instantly share code, notes, and snippets.

@gwils
Forked from tonymorris/jwk.hs
Last active January 11, 2017 04:31
Show Gist options
  • Save gwils/a5ad80d61b3e7868406bb463e5cd0d85 to your computer and use it in GitHub Desktop.
Save gwils/a5ad80d61b3e7868406bb463e5cd0d85 to your computer and use it in GitHub Desktop.
{-# 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