Skip to content

Commit 231d81f

Browse files
committed
new: infoless monad instance
1 parent c752048 commit 231d81f

File tree

1 file changed

+8
-1
lines changed
  • lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat

1 file changed

+8
-1
lines changed

lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/InfoLess.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ module LambdaBuffers.Compiler.ProtoCompat.InfoLess (
77
withInfoLess,
88
withInfoLessF,
99
mkInfoLess,
10-
InfoLessC,
10+
InfoLessC (infoLessId),
1111
) where
1212

13+
import Control.Monad (join)
14+
import Control.Monad.Identity (Identity (Identity))
1315
import Data.Bifunctor (Bifunctor (bimap))
1416
import Data.Default (Default (def))
1517
import Data.Map qualified as M
@@ -66,6 +68,8 @@ import LambdaBuffers.Compiler.ProtoCompat.Types (
6668
newtype InfoLess a = InfoLess {unsafeInfoLess :: a}
6769
deriving stock (Show, Eq, Ord)
6870
deriving stock (Functor, Traversable, Foldable)
71+
deriving (Applicative) via Identity
72+
deriving (Monad) via Identity
6973

7074
{- | SourceInfo Less ID.
7175
A TypeClass that provides id for types with SourceInfo - where SI is defaulted - therefore ignored. Can only be derived.
@@ -90,6 +94,9 @@ withInfoLess (InfoLess a) f = f . unsafeInfoLess . mkInfoLess $ a
9094
withInfoLessF :: forall f {a} {b}. InfoLessC a => InfoLess a -> (a -> f b) -> f b
9195
withInfoLessF (InfoLess a) f = f . unsafeInfoLess . mkInfoLess $ a
9296

97+
instance InfoLessC a => InfoLessC (InfoLess a) where
98+
infoLessId = join . mkInfoLess
99+
93100
instance InfoLessC a => InfoLessC [a] where
94101
infoLessId = fmap infoLessId
95102

0 commit comments

Comments
 (0)