Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active August 12, 2017 09:52
Show Gist options
  • Select an option

  • Save danidiaz/e1173f05b11be80ee0aeff7624dd88a3 to your computer and use it in GitHub Desktop.

Select an option

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
{-# 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