Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Template Haskell #45

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/Data/Active.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down