I want to achieve something similar to the bounded arrays in the standard array package but using repa arrays.
What is the nice and clean way to achieve this?
This is what I tried, but there must be a better way than wrapping everything in custom functions that check for bounds:
import Data.Array.Repa
data C = A | F | L deriving (Eq,Enum,Ord,Bounded,Show)
data Ballot c = Ballot {
vote::Array U (Z :. Int) Int
} deriving Show
mkBallot::(Eq c ,Enum c,Ord c, Bounded c, Show c) => c -> Ballot c
mkBallot c = Ballot $ fromListUnboxed (Z :. max) (genSc c)
where
max = (fromEnum (maxBound `asTypeOf` c)) + 1
genSc::(Eq c,Enum c,Ord c,Bounded c,Show c) => c -> [Int]
genSc c = [ f x | x <- enumFrom (minBound `asTypeOf` c) , let f v = if x == c then 1 else 0]
showScore c b = index (vote b) (Z :. ((fromEnum c)))
Also I have tried to derive a Shape instance for (sh :. C) but to no avail, I can't really get my head around on how to implement some of the interfaces declared in the Shape class for my data type. I am writing the question with the hope that someone else has a way, but if not, I shall try again. Thank you!