Skip to content

Instantly share code, notes, and snippets.

@dariooddenino
Last active October 15, 2018 09:55
Show Gist options
  • Save dariooddenino/ccf96a566cb731cde30a31231deb321e to your computer and use it in GitHub Desktop.
Save dariooddenino/ccf96a566cb731cde30a31231deb321e to your computer and use it in GitHub Desktop.
data ShowProps = ShowProps (forall sym. IsSymbol sym => SProxy sym -> String)
instance showProps ::
(Show a, IsSymbol sym) =>
FoldingWithIndex (ShowProps) (SProxy sym) String a String where
foldingWithIndex (ShowProps fn) prop str a =
pre <> fn prop <> ": " <> show a
where
pre | str == "" = ""
| otherwise = str <> ", "
showRecord :: forall r sym.
IsSymbol sym =>
HFoldlWithIndex (ShowProps) String { | r } String =>
(forall sym2. IsSymbol sym2 => SProxy sym2 -> String) ->
{ | r } ->
String
showRecord fn r =
"{ " <> hfoldlWithIndex (ShowProps fn) "" r <> " }"
bu ::
forall sym a.
FoldingWithIndex ShowProps (SProxy sym) String a String =>
String
bu = showRecord reflectSymbol' { a: "foo", b: 1 }
where
reflectSymbol' :: forall sym2. IsSymbol sym2 => SProxy sym2 -> String
reflectSymbol' = reflectSymbol
-- No type class instance was found for IsSymbol t0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment