Skip to content

Instantly share code, notes, and snippets.

@danbornside
Created March 23, 2019 17:32
Show Gist options
  • Save danbornside/a7d2c1aa2add24a2ef58b81dc5ff11b8 to your computer and use it in GitHub Desktop.
Save danbornside/a7d2c1aa2add24a2ef58b81dc5ff11b8 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Reflex.Patch
import Data.Dependent.Sum
data MyRecord = MyRecord
{ _myField_1 :: Int
, _myField_2 :: String
} deriving (Eq, Ord, Show)
makeLenses 'MyRecord
data MyRecordPatch a where
MyField_1 :: MyRecordPatch Int
MyField_2 :: MyRecordPatch String
myRecordOptics :: MyRecordPatch a -> Lens' MyRecord a
myRecordOptics = \case
MyField_1 -> myField_1
MyField_2 -> myField_2
instance Patch (DSum MyRecordPatch Identity) where
type PatchTarget (DSum MyRecordPatch Identity) = MyRecord
apply p t = Just $ case p of
(field :=> Identity x) -> set (myRecordOptics field) x t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment