genAliases' :: Int -- how many binary aliases 
            -> Int -- how many octal aliases
            -> Int -- how many dec aliases
            -> Int -- how many hex aliases
            -> Int -- maximum alias
            -> Q [Dec]
-- FIXME: genAliases' is ugly!
genAliases' nb no nd nh curr 
 | curr < 0 = return []
 | otherwise = 
    do rest <- genAliases' nb no nd nh (curr-1)
       -- binaries
       restb <- addAliasBase (curr > nb) ('b' : bStr) ('B' : bStr) rest
       -- octals
       resto <- addAliasBase (curr > no) ('o' : oStr) ('O' : oStr) restb
       -- decimals, we don't aliases of the decimal digits
       -- (they are alredy defined in the representation module)
       restd <- if curr > nd then return resto             
                else do val <- genValAlias ('d' : dStr) decRep
                        typ <- genTypeAlias ('D' : dStr) decRep
                        if (curr < 10) then return $ val : resto
                         else return $ val : typ : resto
       -- hexadicimals
       addAliasBase (curr > no) ('h' : hStr) ('H' : hStr) restd
 
 where  -- Add aliases of certain base to the rest of aliases
        addAliasBase cond vStr tStr rest =
          if cond then return rest
          else  do val <- genValAlias vStr decRep
                   typ <- genTypeAlias tStr decRep
                   return $ val : typ : rest

        decRep = dec2TypeLevel curr        

        bStr = toBase Bin curr
        oStr = toBase Oct curr
        dStr = toBase Dec curr
        hStr = toBase Hex curr

-- | Generate the type-level decimal representation for a value-level 
--   natural number. 
-- NOTE: This function could be useful by itself avoiding to generate 
-- aliases. However, type-splicing is not yet supported by template haskell.
genAliases' :: Int -- how many binary aliases 
            -> Int -- how many octal aliases
            -> Int -- how many dec aliases
            -> Int -- how many hex aliases
            -> Int -- maximum alias
            -> Q [Dec]
genAliases' nb no nd nh curr 
 | curr < 0 = return []
 | otherwise = 
    do rest <- genAliases' nb no nd nh (curr-1)
       -- binaries
       restb <- addAliasBase (curr > nb) ('b' : bStr) ('B' : bStr) rest
       -- octals
       resto <- addAliasBase (curr > no) ('o' : oStr) ('O' : oStr) restb
       -- decimals, we don't aliases of the decimal digits
       -- (they are alredy defined in the representation module)
       restd <- if curr > nd then return resto             
                else do val <- genValAlias ('d' : dStr) decRep
                        typ <- genTypeAlias ('D' : dStr) decRep
                        if (curr < 10) then return $ val : resto
                         else return $ val : typ : resto
       -- hexadicimals
       addAliasBase (curr > no) ('h' : hStr) ('H' : hStr) restd
 
 where  -- Add aliases of certain base to the rest of aliases
        addAliasBase cond vStr tStr rest =
          if cond then return rest
          else  do val <- genValAlias vStr decRep
                   typ <- genTypeAlias tStr decRep
                   return $ val : typ : rest

        decRep = dec2TypeLevel curr        

        bStr = toBase Bin curr
        oStr = toBase Oct curr
        dStr = toBase Dec curr
        hStr = toBase Hex curr

-- | Generate the type-level decimal representation for a value-level 
--   natural number. 
-- NOTE: This function could be useful by itself avoiding to generate 
-- aliases. However, type-splicing is not yet supported by template haskell.
genAliases' nb no nd nh curr 
 | curr < 0 = return []
 | otherwise = 
    do rest <- genAliases' nb no nd nh (curr-1)
       -- binaries
       restb <- addAliasBase (curr > nb) ('b' : bStr) ('B' : bStr) rest
       -- octals
       resto <- addAliasBase (curr > no) ('o' : oStr) ('O' : oStr) restb
       -- decimals, we don't aliases of the decimal digits
       -- (they are alredy defined in the representation module)
       restd <- if curr > nd then return resto             
                else do val <- genValAlias ('d' : dStr) decRep
                        typ <- genTypeAlias ('D' : dStr) decRep
                        if (curr < 10) then return $ val : resto
                         else return $ val : typ : resto
       -- hexadicimals
       addAliasBase (curr > no) ('h' : hStr) ('H' : hStr) restd
 
 where  -- Add aliases of certain base to the rest of aliases
        addAliasBase cond vStr tStr rest =
          if cond then return rest
          else  do val <- genValAlias vStr decRep
                   typ <- genTypeAlias tStr decRep
                   return $ val : typ : rest

        decRep = dec2TypeLevel curr        

        bStr = toBase Bin curr
        oStr = toBase Oct curr
        dStr = toBase Dec curr
        hStr = toBase Hex curr

-- | Generate the type-level decimal representation for a value-level 
--   natural number. 
-- NOTE: This function could be useful by itself avoiding to generate 
-- aliases. However, type-splicing is not yet supported by template haskell.