Last active
August 12, 2017 09:52
-
-
Save danidiaz/e1173f05b11be80ee0aeff7624dd88a3 to your computer and use it in GitHub Desktop.
IsRecord constraint using generics-sop type-level metadata. Related to https://gist.github.com/danidiaz/3f396f92a6dda1cff87639ec4f1194df
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 ConstraintKinds #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| module Soapy (IsRecord) where | |
| import GHC.TypeLits (Symbol) | |
| import Generics.SOP | |
| import qualified Generics.SOP.Type.Metadata as T | |
| type IsRecord (r :: *) (mn :: Symbol) (dn :: Symbol) (cn :: Symbol) (fs :: [T.FieldInfo]) (xs :: [*]) = | |
| (IsProductType r xs, DatatypeInfoOf r ~ T.ADT mn dn '[T.Record cn fs], T.DemoteFieldInfos fs xs) | |
| -- Use T.demoteFieldInfos to get a n-ary product with the names of the constructors. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment