Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 3e53644

Browse files
committed
Define block using a newtype helper.
We can’t rely on having a Semigroup instance for the term type.
1 parent 1e3e8dd commit 3e53644

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

semantic-core/src/Data/Core.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE DeriveGeneric, DeriveTraversable, FlexibleContexts, LambdaCase, MultiParamTypeClasses, OverloadedStrings, QuantifiedConstraints, RankNTypes,
2-
ScopedTypeVariables, StandaloneDeriving, TypeFamilies, TypeOperators #-}
2+
ScopedTypeVariables, StandaloneDeriving, TypeFamilies, TypeOperators, UndecidableInstances #-}
33
module Data.Core
44
( Core(..)
55
, CoreF(..)
@@ -41,7 +41,6 @@ import Data.Coerce
4141
import Data.Foldable (foldl')
4242
import Data.List.NonEmpty
4343
import Data.Loc
44-
import Data.Maybe
4544
import Data.Name
4645
import Data.Scope
4746
import Data.Stack
@@ -127,8 +126,13 @@ infixl 4 :.
127126
let' :: (Carrier sig m, Member CoreF sig) => User -> m a
128127
let' = send . Let
129128

130-
block :: (Foldable t, Carrier sig m, Member CoreF sig, Semigroup (m a)) => t (m a) -> m a
131-
block = fromMaybe unit . foldMap Just
129+
block :: (Foldable t, Carrier sig m, Member CoreF sig) => t (m a) -> m a
130+
block = maybe unit getBlock . foldMap (Just . Block)
131+
132+
newtype Block m a = Block { getBlock :: m a }
133+
134+
instance (Carrier sig m, Member CoreF sig) => Semigroup (Block m a) where
135+
Block a <> Block b = Block (send (a :>> b))
132136

133137
lam :: (Eq a, Carrier sig m, Member CoreF sig) => Named a -> m a -> m a
134138
lam (Named u n) b = send (Lam u (bind1 n b))

0 commit comments

Comments
 (0)