From acfc7281b5a65c795678804f905479d1fd2c0a9d Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 27 Feb 2020 13:02:27 +0100 Subject: [PATCH] Better constructor for enumerations in optics (#115) --- core/optics/src/Mu/Schema/Optics.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/optics/src/Mu/Schema/Optics.hs b/core/optics/src/Mu/Schema/Optics.hs index 0638ce2..4fe9f06 100644 --- a/core/optics/src/Mu/Schema/Optics.hs +++ b/core/optics/src/Mu/Schema/Optics.hs @@ -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))