Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Last active January 11, 2017 04:30
Show Gist options
  • Save tonymorris/c99fc28ab2694d632c4a37011c4a1086 to your computer and use it in GitHub Desktop.
Save tonymorris/c99fc28ab2694d632c4a37011c4a1086 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
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