Skip to content

Commit

Permalink
Generalize typing of Array.alloc and HashMap.empty
Browse files Browse the repository at this point in the history
Replacing response type `Ur b` by simply `b` also checks and enables
uses like
```haskell
let (i, _) = HashMap.empty 100 (\ env -> runState (eval e) env)
```
(see issue tweag#404).

Caveat: I am relying on the linea type checker (which might be in
alpha state, dunno), so there might be reasons unknown to me why this
generalization is invalid.  Test suite passes, though.
  • Loading branch information
andreasabel committed Apr 12, 2022
1 parent 4668017 commit 44865c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Data/Array/Mutable/Linear/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ alloc ::
HasCallStack =>
Int ->
a ->
(Array a %1 -> Ur b) %1 ->
Ur b
(Array a %1 -> b) %1 ->
b
alloc s x f
| s < 0 =
(error ("Array.alloc: negative size: " ++ show s) :: x %1 -> x)
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Array/Mutable/Unlifted/Linear.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ infixr 0 `lseq` -- same fixity as base.seq
-- | Allocate a mutable array of given size using a default value.
--
-- The size should be non-negative.
alloc :: Int -> a -> (Array# a %1 -> Ur b) %1 -> Ur b
alloc :: Int -> a -> (Array# a %1 -> b) %1 -> b
alloc (GHC.I# s) a f =
let new = GHC.runRW# Prelude.$ \st ->
case GHC.newArray# s a st of
Expand Down
4 changes: 2 additions & 2 deletions src/Data/HashMap/Mutable/Linear/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ empty ::
forall k v b.
Keyed k =>
Int ->
(HashMap k v %1 -> Ur b) %1 ->
Ur b
(HashMap k v %1 -> b) %1 ->
b
empty size scope =
let cap = max 1 size
in Array.alloc cap Nothing (\arr -> scope (HashMap 0 cap arr))
Expand Down

0 comments on commit 44865c1

Please sign in to comment.