Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save pbrisbin/593213bbf04dc7d016ce to your computer and use it in GitHub Desktop.

Select an option

Save pbrisbin/593213bbf04dc7d016ce to your computer and use it in GitHub Desktop.
Follow the types
2014-07-17 15:05:03 darthdeus guys I'm getting No instance for (Text.Julius.ToJavascript …Data.ByteString.Lazy.Internal.ByteString) when using aeson's encode ... how should I convert things to json so that I can interpolate them in julius?
2014-07-17 15:05:38 darthdeus should i unpack the bytestring and pack it into Text? (seems inefficient)
2014-07-17 15:09:25 darthdeus hmm seems lazy Text doesn't work either
2014-07-17 15:16:40 darthdeus aaargh, string doesn't work either
2014-07-17 15:16:55 brisbin String and Text should both be interpolatable
2014-07-17 15:17:10 darthdeus No instance for (Text.Julius.ToJavascript String) … arising from a use of ‘Text.Julius.toJavascript’
2014-07-17 15:17:18 darthdeus after doing this
2014-07-17 15:17:25 darthdeus let json = TL.unpack $ decodeUtf8 $ encode reports :: String
2014-07-17 15:17:32 darthdeus inside the .julius file just #{json}
2014-07-17 15:21:52 brisbin just looking at the docs, RawJavascript has an instance for ToJavascript
2014-07-17 15:22:00 brisbin and Text/String have instances for RawJS
2014-07-17 15:22:17 brisbin so #{rawJS json} may work for you
2014-07-17 15:22:36 brisbin however
2014-07-17 15:22:43 brisbin Value also has an instance for ToJavascript
2014-07-17 15:22:50 brisbin so you don't need the encode/unpack dance
2014-07-17 15:22:55 brisbin just put the Value in the interpolation
2014-07-17 15:23:13 darthdeus it will automatically serialize to json?
2014-07-17 15:23:25 brisbin i'm just looking at the types, i have no idea what it will do
2014-07-17 15:24:27 brisbin #{toJSON reports}, see what happens
2014-07-17 15:26:26 darthdeus oh wow that works, thanks :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment