foundation icon indicating copy to clipboard operation
foundation copied to clipboard

Generalize String builder to Array builder

Open vincenthz opened this issue 8 years ago • 2 comments

related to #324

vincenthz avatar Jun 13 '17 05:06 vincenthz

I'm interested in implementing this Builder. But at first let me check if I am getting the issue right. I will need to rewrite Foundation.String.Builder module for generalized builder which will work for UArray and String both? So builder type will look like this

data Builder a = E a | T [Builder a]

and having the following type family

type family Element t

type instance Element (UArray ty) = ty
type instance Element String      = Char

Function

emitChar :: Char -> Builder

will now become

emitElement :: Element a -> Builder a

?

vrom911 avatar Oct 08 '17 22:10 vrom911

yes, that's correct @vrom911. one thing that is orthogonal but thought I would mention is that the approach used in this builder is not very efficient and if you want inspiration for more efficient builder implementations there's http://hackage.haskell.org/package/bytestring-0.10.2.0/docs/Data-ByteString-Builder.html or http://hackage.haskell.org/package/blaze-builder-0.4.0.2/docs/Blaze-ByteString-Builder.html that comes to mind.

vincenthz avatar Oct 09 '17 14:10 vincenthz