From 6b468705d15a15f10caf21939a32edd39bbd9061 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Thu, 23 Nov 2023 13:01:16 +0000 Subject: [PATCH] Avoid all use of Template Haskell The new code comes from expanding the old splices and performing some basic cleanup. This has various advantages, from improving compilation times to making cross-compilation vastly simpler. --- src/Data/Active.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Data/Active.hs b/src/Data/Active.hs index 100ded3..a37ca77 100644 --- a/src/Data/Active.hs +++ b/src/Data/Active.hs @@ -5,7 +5,6 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeSynonymInstances #-} @@ -169,7 +168,10 @@ import Linear.Affine newtype Time n = Time { unTime :: n } deriving (Eq, Ord, Show, Read, Enum, Num, Fractional, Real, RealFrac, Functor) -makeWrapped ''Time +instance Wrapped (Time a) where + type Unwrapped (Time a) = a + _Wrapped' = iso unTime Time +instance Rewrapped (Time a) (Time b) -- | A convenient wrapper function to convert a numeric value into a time. toTime :: n -> Time n @@ -219,7 +221,10 @@ instance Affine Time where (Time t1) .-. (Time t2) = Duration (t1 - t2) (Time t) .+^ (Duration d) = Time (t + d) -makeWrapped ''Duration +instance Wrapped (Duration a) where + type Unwrapped (Duration a) = a + _Wrapped' = iso fromDuration toDuration +instance Rewrapped (Duration a) (Duration b) -- | An @Era@ is a concrete span of time, that is, a pair of times -- representing the start and end of the era. @Era@s form a @@ -330,7 +335,10 @@ shiftDynamic sh = newtype Active a = Active (MaybeApply Dynamic a) deriving (Functor, Apply, Applicative) -makeWrapped ''Active +instance Wrapped (Active a) where + type Unwrapped (Active a) = MaybeApply Dynamic a + _Wrapped' = iso (\(Active a) -> a) Active +instance Rewrapped (Active a) (Active b) active :: Iso' (Active a) (Either (Dynamic a) a) active = _Wrapped . iso runMaybeApply MaybeApply