Yesod: Can I list the Haskell list in Julia?

I have a list of coordinates that I need to put on the map. Is it possible to repeat the list in julius? Right now I am creating a hidden table in a tree and accessing this table in julius, which does not seem to be the ideal solution. Can anyone point out a better solution? Thank.

edit: Passing a JSON string for a list (which can be read by julius) seems to solve my problem.

+3
source share
1 answer

As far as I know, you cannot iterate over a list directly in julius. However, you can use a Monoid instance for a type Javascriptto achieve a similar effect. For instance:

import Text.Julius
import Data.Monoid
rows :: [Int] -> t -> Javascript
rows xs = mconcat $ map row xs
  where
    row x = [julius|v[#{show x}] = #{show x};
|]

rows xs , julius. , ghci:

> renderJavascript $ rows [1..5] ()
"v[1] = 1;\nv[2] = 2;\nv[3] = 3;\nv[4] = 4;\nv[5] = 5;\n"
+2

All Articles