Changes between Version 22 and Version 23 of TypeNats/Basics


Ignore:
Timestamp:
Mar 21, 2012 12:59:34 AM (2 years ago)
Author:
diatchki
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TypeNats/Basics

    v22 v23  
    9393{{{ 
    9494memset :: Storable a => ArrPtr n a -> a -> TNat n -> IO () 
    95 memset = ... 
     95memset (ArrPtr p) a n = mapM_ (\i -> pokeElemOff p i a) 
     96                                   [ 0 .. fromIntegral (tNatInteger n - 1) ] 
    9697}}} 
    9798 
    9899This style is, basically, a more typed version of what is found in many standard C libraries. 
    99100Callers of this function have to pass the size of the array explicitly, and the type system checks that the 
    100 size matches that of the array. When defining {{{memset}}} we can just use {{{tNatInteger}}}` on the {{{TNat n}}} 
    101 parameter to get the actual value of the array size. 
     101size matches that of the array.  Note that in the implementation of {{{memset}}} we used {{{tNatInteger}}} 
     102to get the concrete integer associated with the singleton type. 
    102103 
    103 Another approach is to let the system infer the parameter by using the class `NatI`.  For example: 
     104Another approach is to let the system infer the parameter by using the class {{{NatI}}}.  For example: 
    104105{{{ 
    105106memsetAuto :: (Storable a, NatI n) => ArrPtr n a -> a -> IO () 
    106 memsetAuto = ... 
     107memsetAuto ptr a = withTNat (memset arr a) 
    107108}}} 
    108109