I have the following source code:
{-
Essentially, the goal is to take an Int and convert it to one of the data types defined above. The incSize function works correctly; it increases the size by one. The inToSize'' function also works; it will increase the given number by 3. However, both intToSize and intToSize' do not work; GHCI describes their types as described above (and obviously a + 1 = / = a). Iβm not sure that manual recording of the composition works correctly, while something else will not work (functions that I have defined as not compiled, but will always give an error when they are used.) The use should look something like this:
> :t intToSize'' (undefined :: Zero) > intToSize'' (undefined :: Zero) :: Three
However, the ultimate goal is to write a function that takes a list and gives a data type that encodes the length of the list by type (essentially a vector):
data Vect sv = Vect v instance forall sv . Show (Vect sv) where --toInt is a function which takes a type number and returns its data level value show (Vect v) = "Vect " ++ (show . toInt) (undefined :: s) ++ show v > let l = [1,2,3,4,5] > vector l > Vect 5 [1,2,3,4,5]
You may have noticed that the code is missing; it's pretty boring to watch, so I turn it on below.
instance Sum Zero Zero Zero instance Sum Zero One One instance Sum Zero Two Two instance Sum Zero Three Three instance Sum Zero Four Four instance Sum Zero Five Five instance Sum Zero Six Six instance Sum One Zero One instance Sum One One Two instance Sum One Two Three instance Sum One Three Four instance Sum One Four Five instance Sum One Five Six instance Sum Two Zero Two instance Sum Two One Three instance Sum Two Two Four instance Sum Two Three Five instance Sum Two Four Six instance Sum Three Zero Three instance Sum Three One Four instance Sum Three Two Five instance Sum Three Three Six instance Sum Four Zero Four instance Sum Four One Five instance Sum Four Two Six instance Sum Five Zero Five instance Sum Five One Six instance Sum Six Zero Six
source share