Skip to content

Commit df58135

Browse files
authored
Make it compile with MicroHs (#81)
1 parent 82b72a7 commit df58135

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ on:
1010

1111
jobs:
1212
build:
13+
name: ghc-${{ matrix.ghc }}
1314
runs-on: ubuntu-latest
1415
strategy:
1516
fail-fast: false
1617
matrix:
1718
ghc: ['8.0', '8.2', '8.4', '8.6', '8.8', '8.10', '9.0', '9.2', '9.4', '9.6', '9.8', '9.10', '9.12']
1819
steps:
19-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v5
2021
- uses: haskell-actions/setup@v2
2122
id: setup-haskell
2223
with:
@@ -29,3 +30,24 @@ jobs:
2930
key: ${{ runner.os }}-${{ matrix.ghc }}
3031
- name: Build
3132
run: cabal build
33+
34+
mhs:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v5
38+
with:
39+
path: parallel
40+
- name: Checkout MicroHs repository
41+
uses: actions/checkout@v5
42+
with:
43+
repository: augustss/MicroHs
44+
path: mhs
45+
- name: Install MicroHs
46+
run: |
47+
cd mhs
48+
make minstall
49+
echo "$HOME/.mcabal/bin" >> $GITHUB_PATH
50+
- name: Build
51+
run: |
52+
cd parallel
53+
mcabal -r build

Control/Parallel.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ module Control.Parallel (
2828

2929
#ifdef __GLASGOW_HASKELL__
3030
import qualified GHC.Conc (par, pseq)
31+
#endif
3132

3233
infixr 0 `par`, `pseq`
33-
#endif
3434

3535
-- Maybe parIO and the like could be added here later.
3636

@@ -54,7 +54,7 @@ par :: a -> b -> b
5454
#ifdef __GLASGOW_HASKELL__
5555
par = GHC.Conc.par
5656
#else
57-
-- For now, Hugs does not support par properly.
57+
-- For now, Hugs and MicroHs don't support par properly.
5858
par a b = b
5959
#endif
6060

Control/Parallel/Strategies.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,17 @@ module Control.Parallel.Strategies (
146146
NFData
147147
) where
148148

149-
#if !MIN_VERSION_base(4,8,0)
149+
#if defined(__MHS__) || !MIN_VERSION_base(4,8,0)
150150
import Data.Traversable
151+
#endif
152+
#if !MIN_VERSION_base(4,8,0)
151153
import Control.Applicative
152154
#endif
153155
import Control.Parallel
154156
import Control.DeepSeq (NFData(rnf))
155157
import Control.Monad.Fix (MonadFix (..))
156158

157-
#if MIN_VERSION_base(4,4,0)
159+
#if defined(__GLASGOW_HASKELL__) && MIN_VERSION_base(4,4,0)
158160
import System.IO.Unsafe (unsafeDupablePerformIO)
159161
import Control.Exception (evaluate)
160162
#else
@@ -164,8 +166,10 @@ import Control.Monad
164166

165167
import qualified Control.Seq
166168

169+
#ifdef __GLASGOW_HASKELL__
167170
import GHC.Exts
168171
import GHC.IO (IO (..))
172+
#endif
169173

170174
infixr 9 `dot` -- same as (.)
171175
infixl 0 `using` -- lowest precedence and associate to the left
@@ -280,7 +284,11 @@ instance Applicative Eval where
280284

281285
instance Monad Eval where
282286
return = pure
287+
# ifdef __GLASGOW_HASKELL__
283288
Done x >>= k = lazy (k x) -- Note: pattern 'Done x' makes '>>=' strict
289+
# else
290+
Done x >>= k = k x
291+
# endif
284292

285293
instance MonadFix Eval where
286294
mfix f = let r = f (runEval r) in r
@@ -463,10 +471,14 @@ rdeepseq x = do rseq (rnf x); return x
463471

464472
-- | 'rpar' sparks its argument (for evaluation in parallel).
465473
rpar :: Strategy a
474+
#ifdef __GLASGOW_HASKELL__
466475
#if __GLASGOW_HASKELL__ >= 702
467-
rpar x = Eval $ IO $ \s -> spark# x s
476+
rpar x = Eval $ IO $ \s -> spark# x s
477+
#else
478+
rpar x = case (par# x) of _ -> Done x
479+
#endif
468480
#else
469-
rpar x = case (par# x) of { _ -> Done x }
481+
rpar x = case par x () of () -> Done x
470482
#endif
471483
{-# INLINE rpar #-}
472484

Control/Seq.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module Control.Seq
5959
) where
6060

6161
import Control.DeepSeq (NFData, deepseq)
62-
#if MIN_VERSION_base(4,8,0)
62+
#if defined(__GLASGOW_HASKELL__) && MIN_VERSION_base(4,8,0)
6363
import Data.Foldable (toList)
6464
#else
6565
import Data.Foldable (Foldable, toList)

parallel.cabal

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tested-with:
2525
GHC == 8.4.4
2626
GHC == 8.2.2
2727
GHC == 8.0.2
28+
MHS
2829

2930
description:
3031
This package provides a library for parallel programming.
@@ -68,6 +69,3 @@ library
6869
if impl(ghc >= 6.11)
6970
-- To improve parallel performance:
7071
ghc-options: -feager-blackholing
71-
72-
if impl(ghc >= 7.2.1)
73-
build-depends: ghc-prim

0 commit comments

Comments
 (0)