Changes between Version 22 and Version 23 of TypeNats/Basics
 Timestamp:
 Mar 21, 2012 12:59:34 AM (5 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

TypeNats/Basics
v22 v23 93 93 {{{ 94 94 memset :: Storable a => ArrPtr n a > a > TNat n > IO () 95 memset = ... 95 memset (ArrPtr p) a n = mapM_ (\i > pokeElemOff p i a) 96 [ 0 .. fromIntegral (tNatInteger n  1) ] 96 97 }}} 97 98 98 99 This style is, basically, a more typed version of what is found in many standard C libraries. 99 100 Callers 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.101 size matches that of the array. Note that in the implementation of {{{memset}}} we used {{{tNatInteger}}} 102 to get the concrete integer associated with the singleton type. 102 103 103 Another approach is to let the system infer the parameter by using the class `NatI`. For example:104 Another approach is to let the system infer the parameter by using the class {{{NatI}}}. For example: 104 105 {{{ 105 106 memsetAuto :: (Storable a, NatI n) => ArrPtr n a > a > IO () 106 memsetAuto = ...107 memsetAuto ptr a = withTNat (memset arr a) 107 108 }}} 108 109