Академический Документы
Профессиональный Документы
Культура Документы
Don Stewart
Galois Inc
Haskell's Data Types
● Beautiful algebraic data types:
data Set a
= Tip
| Bin !Int a !(Set a) !(Set a)
data MBUArr s e =
MBUArr !Int
(MutableByteArray# s)
● Fill the mutable array, freeze it, and get free substrings,
and persistance.
● Low level Haskell
Primitive operations
length :: BUArr e -> Int
length (BUArr _ n _) = n
unsafeFreezeMBU
:: MBUArr s e -> Int -> ST s (BUArr e)
data UArr e
data MUArr e :: * -> *
newU :: UA e
=> Int
-> (forall s. MUArr e s -> ST s Int)
-> UArr e
newU n init =
runST (do
ma <- newMU n
n' <- init ma
freezeMU ma n'
)
lengthU (UAUnit n) = n
indexU (UAUnit _) _ = ()
sliceU (UAUnit _) _ n = UAUnit n
lengthMU (MUAUnit n) = n
newMU n = return $ MUAUnit n
readMU (MUAUnit _) _ = return ()
writeMU (MUAUnit _) _ _= return ()
indexU (UAProd l r) i =
indexU l i :*: indexU r i
Support for numeric stuff
instance (RealFloat a, UA a)
=> UA (Complex a) where
next i | i == n = Done
| otherwise = Yield (arr `indexU` i) (i+1)
"streamU/unstreamU" forall s.
streamU (unstreamU s) = s
optimisations
● Arrays at the end will be fused from the
zipWithS
:: (a -> b -> c) -> Stream a -> Stream b -> Stream c
It's on hackage.haskell.org