Skip to content

Commit 4583e76

Browse files
authored
Merge pull request #565 from Tjalle-S/update-stdlib
Small updates to standard library
2 parents 97771c3 + 4f660dc commit 4583e76

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/Data/Array/Accelerate.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE ExplicitNamespaces #-}
13
{-# LANGUAGE PatternSynonyms #-}
24
{-# LANGUAGE ScopedTypeVariables #-}
35
{-# LANGUAGE TypeApplications #-}
@@ -411,7 +413,10 @@ module Data.Array.Accelerate (
411413

412414
-- ---------------------------------------------------------------------------
413415
-- * Useful re-exports
414-
(.), ($), (&), flip, error, undefined, const, otherwise,
416+
(.), ($), (&), flip, error, undefined, const, id, otherwise,
417+
#if __GLASGOW_HASKELL__ >= 904
418+
type (~),
419+
#endif
415420
Show, Generic, HasCallStack,
416421
fromString, -- -XOverloadedStrings
417422
fromListN, -- -XOverloadedLists
@@ -463,7 +468,10 @@ import qualified Data.Array.Accelerate.Sugar.Array as S
463468
import qualified Data.Array.Accelerate.Sugar.Shape as S
464469

465470
import Data.Function ( (&) )
466-
import Prelude ( (.), ($), Char, Show, flip, undefined, error, const, otherwise )
471+
#if __GLASGOW_HASKELL__ >= 904
472+
import Data.Type.Equality ( type (~) )
473+
#endif
474+
import Prelude ( (.), ($), Char, Show, flip, undefined, error, const, id, otherwise )
467475

468476
import GHC.Exts ( fromListN, fromString )
469477
import GHC.Generics ( Generic )

src/Data/Array/Accelerate/Classes/Eq.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ instance Eq Z where
119119
_ == _ = True_
120120
_ /= _ = False_
121121

122+
instance (Shape sh) => Eq (Any sh) where
123+
_ == _ = True_
124+
_ /= _ = False_
125+
126+
instance Eq All where
127+
_ == _ = True_
128+
_ /= _ = False_
129+
130+
122131
-- Instances of 'Prelude.Eq' don't make sense with the standard signatures as
123132
-- the return type is fixed to 'Bool'. This instance is provided to provide
124133
-- a useful error message.
@@ -203,7 +212,7 @@ runQ $ do
203212
ts <- mapM mkTup [2..16]
204213
return $ concat (concat [is,fs,ns,cs,ts])
205214

206-
instance Eq sh => Eq (sh :. Int) where
215+
instance (Eq sh, Eq i) => Eq (sh :. i) where
207216
x == y = indexHead x == indexHead y && indexTail x == indexTail y
208217
x /= y = indexHead x /= indexHead y || indexTail x /= indexTail y
209218

src/Data/Array/Accelerate/Control/Monad.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Data.Array.Accelerate.Control.Monad (
2525
-- ** Basic functions
2626
(=<<), (>>),
2727
(>=>), (<=<),
28+
join,
2829

2930
-- ** Conditional execution of monadic expressions
3031
when, unless,
@@ -40,7 +41,7 @@ import Data.Array.Accelerate.Language
4041
import Data.Array.Accelerate.Sugar.Elt
4142
import Data.Array.Accelerate.Smart
4243

43-
import Prelude ( Bool, flip )
44+
import Prelude ( Bool, flip, id )
4445

4546

4647
-- | The 'Monad' class is used for scalar types which can be sequenced.
@@ -134,6 +135,19 @@ infixr 1 <=<
134135
-> (Exp a -> Exp (m c))
135136
(<=<) = flip (>=>)
136137

138+
-- | The 'join' function is the conventional monad join operator. It
139+
-- is used to remove one level of monadic structure, projecting its
140+
-- bound argument into the outer level.
141+
--
142+
-- \'@'join' bss@\' can be understood as the @do@ expression
143+
--
144+
-- @
145+
-- do bs <- bss
146+
-- bs
147+
-- @
148+
--
149+
join :: (Monad m, Elt a, Elt (m a), Elt (m (m a))) => Exp (m (m a)) -> Exp (m a)
150+
join = (>>= id)
137151

138152
-- | Conditional execution of a monadic expression
139153
--

src/Data/Array/Accelerate/Data/Maybe.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ instance Ord a => Ord (Maybe a) where
130130
go Nothing_ Just_{} = LT_
131131
go Just_{} Nothing_{} = GT_
132132

133-
instance (Monoid (Exp a), Elt a) => Monoid (Exp (Maybe a)) where
133+
instance (Semigroup (Exp a), Elt a) => Monoid (Exp (Maybe a)) where
134134
mempty = Nothing_
135135

136136
instance (Semigroup (Exp a), Elt a) => Semigroup (Exp (Maybe a)) where

0 commit comments

Comments
 (0)