Better constructor for enumerations in optics (#115)

This commit is contained in:
Alejandro Serrano 2020-02-27 13:02:27 +01:00 committed by GitHub
parent 4444d6d85d
commit acfc7281b5

View File

@ -1,9 +1,10 @@
{-# language AllowAmbiguousTypes #-}
{-# language DataKinds #-}
{-# language FlexibleInstances #-}
{-# language FunctionalDependencies #-}
{-# language GADTs #-}
{-# language KindSignatures #-}
{-# language LambdaCase #-}
{-# language PolyKinds #-}
{-# language ScopedTypeVariables #-}
{-# language TypeApplications #-}
{-# language TypeOperators #-}
@ -31,8 +32,7 @@ as values in the schema type.
-}
module Mu.Schema.Optics (
-- * Build a term
record
, record1
record, record1, enum
, _U0, _Next, _U1, _U2, _U3
-- * Re-exported for convenience.
, module Optics.Core
@ -176,6 +176,11 @@ instance (r ~ NS (FieldValue w sch) choices)
typeLensGet (FUnion x) = x
typeLensSet = FUnion
enum :: forall (choiceName :: Symbol) choices w sch name.
EnumLabel choices choiceName
=> Term w sch ('DEnum name choices)
enum = TEnum $ enumPrismBuild (Proxy @choiceName)
instance (EnumLabel choices choiceName, r ~ ())
=> LabelOptic choiceName A_Prism
(Term w sch ('DEnum name choices))