{-# LANGUAGE PatternSignatures #-}
{-# LANGUAGE TypeOperators #-}
{- 
Purpose:
  Prototype of Array which is defined over the complete range of the indices.
-}

import Array

data ArithVar -- non-terminals in grammar.
  = Factor
  | Term
  | Expr
  deriving(Enum,Show,Ord,Eq,Bounded,Ix)

data GramArity0 var_type
  = GramOne -- epsilon in compiler texts, i.e. the empty string.
  | GramVar var_type --a non-terminal, i.e. a var_type.
  deriving(Show)

type GramEqs var_type = Array var_type (GramArity0 var_type)
type GramEq var_type  = (var_type,(GramArity0 var_type))

array_complete::(Ix var_type,Bounded var_type)=> [GramEq var_type] -> (GramEqs var_type)

array_complete eqs 
  = array 
    ( minBound::(Bounded var_type)=>var_type
    , maxBound::(Bounded var_type)=>var_type
    ) --the complete range of the indices
    eqs -- the equations (pairs of index ahd value type[GramArity0 var_type])

main = 
  do
  { print Expr
  ; print 
    ( array_complete
      [ (Factor,GramOne)
      , (Term,(GramVar Term))
      , (Expr,GramOne)
      , (Term,GramOne) --this overwrites previous value for Term
      ]
    )
  ;}
