Skip to content

Commit

Permalink
Int constraint in Shape class for type inference
Browse files Browse the repository at this point in the history
This allows the compiler to infer that this instance is used,
before knowing the type of 'i'.
The constraint will then still asure that i is an Int.

With this change, type inferencing will now correctly infer the shape of
use $ fromList (Z :. 10) [0 :: Int ..]
  • Loading branch information
ivogabe committed May 7, 2021
1 parent b96bac8 commit 9ece31c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Data/Array/Accelerate/Sugar/Shape.hs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ instance Shape Z where
sliceAnyIndex = R.SliceNil
sliceNoneIndex = R.SliceNil

instance Shape sh => Shape (sh:.Int) where
-- Note that the constraint 'i ~ Int' allows the compiler to infer that
-- the right argument of ':.' should be an Int.
-- The compiler can now infer that this instance is used, before knowing
-- the type of 'i'.
--
instance (Shape sh, i ~ Int) => Shape (sh:.i) where
shapeR = R.ShapeRsnoc (shapeR @sh)
sliceAnyIndex = R.SliceAll (sliceAnyIndex @sh)
sliceNoneIndex = R.SliceFixed (sliceNoneIndex @sh)
Expand Down

0 comments on commit 9ece31c

Please sign in to comment.