Modifying formatters in Haskell's formatting library -


i'm using chris done's formatting library (specifically formatting-6.0.0). i'm finding difficult construct `higher order' function maps formatter list formatter, performing custom action on resultant list of builders:

list :: ([builder] -> builder) -> format r (a -> r) -> format r ([a] -> r) 

this desirable because allows me embed builder formatting logic in format string.

as example, suppose builder function mconcat. format (list mconcat int) [1,2,3] yield "123". in practice, may use builder function formats list english list, such output above input "1, 2 , 3".

thanks help!

let's expand out format types list :: ([builder] -> builder) -> format r (a -> r) -> format r ([a] -> r)

 format            r     (a -> r) -> format            r     ([a] -> r)  holey  builder    r     (a -> r) -> holey  builder    r     ([a] -> r) (      (builder -> r) -> (a -> r))->(      (builder -> r) -> ([a] -> r)) 

we can try build definition of list.

list append m = holey $ \k -> ... 

we need return [a] -> r ... is. don't have many possible moves because know nothing type r. can pass k :: builder -> r runhm m a -> r. if map on [a] have [r], know nothing r, can't it.

if function list exists has different type ([builder] -> builder) -> format r (a -> r) -> format r ([a] -> r).


we can define list different type list :: ([builder] -> builder) -> format builder (a -> builder) -> format r ([a] -> r). should work first arguments since of formatting components universally qualified on r.

list append m = holey $ \k -> k . append . map (runhm m id) 

this can written more succinctly as

list append m = later (append . map (bprint m)) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -