Last active
January 18, 2019 16:37
-
-
Save smatting/6bcf883fb6b6d55907fd03bd3b17ecea to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DeriveGeneric #-} | |
| -- {-# LANGUAGE FlexibleInstances #-} | |
| -- {-# LANGUAGE UndecidableInstances #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| -- {-# LANGUAGE StandaloneDeriving #-} | |
| {-# LANGUAGE DefaultSignatures #-} | |
| module Foo.Gen | |
| where | |
| import GHC.Generics | |
| class Encode' f where | |
| encode' :: f p -> [Bool] | |
| instance Encode' V1 where | |
| encode' x = undefined | |
| instance Encode' U1 where | |
| encode' U1 = [] | |
| instance (Encode' f, Encode' g) => Encode' (f :+: g) where | |
| encode' (L1 x) = False : encode' x | |
| encode' (R1 x) = True : encode' x | |
| instance (Encode' f, Encode' g) => Encode' (f :*: g) where | |
| encode' (x :*: y) = encode' x ++ encode' y | |
| instance (Encode c) => Encode' (K1 i c) where | |
| encode' (K1 x) = encode x | |
| class Encode a where | |
| encode :: a -> [Bool] | |
| default encode :: (Generic a) => a -> [Bool] | |
| encode x = encode' (from x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment