dynamic 0.0.1 → 0.0.2
raw patch · 3 files changed
+58/−4 lines, 3 files
Files
- README.md +44/−3
- dynamic.cabal +1/−1
- src/Dynamic.hs +13/−0
README.md view
@@ -12,10 +12,24 @@ Launch `ghci`, the interactive REPL for Haskell. -> import Dynamic+``` haskell+import Dynamic+``` +Don't forget to enable `OverloadedStrings`:++``` haskell+:set -XOverloadedStrings+```+ Now you're ready for dynamicness! +## The Dynamic type++In the `dynamic` package there is one type: `Dynamic`!++What, you were expecting something more? Guffaw!+ ## Make dynamic values as easy as pie! Primitive values are easy via regular literals:@@ -145,6 +159,15 @@ That's better! +Heterogenous lists are what life is about:++``` haskell+> toCsv [ 1, "Chris" ]+"1.0\r\nChris\r\n"+```++I can't handle it!!!+ ## Modifying and updating records Use `modify` or `set` to massage data into something more palatable.@@ -196,6 +219,24 @@ [1,2,3,4,5] ``` -## Coming soon+## Append things together -Monoid instances so we can append `Dynamic`s together!+Like in JavaScript, we try to do our best to make something out of appending...++``` haskell+> "Wat" <> 1 <> "!" <> Null :: Dynamic+"Wat1!"+```++## Suspicious?++It's real! This code runs just fine:++``` haskell+silly a =+ if a > 0+ then toJsonFile "out.txt" "Hi"+ else toJsonFile "out.txt" (5 + "a")+```++That passes [the dynamic typing test](https://stackoverflow.com/a/27791387).
dynamic.cabal view
@@ -1,5 +1,5 @@ name: dynamic-version: 0.0.1+version: 0.0.2 synopsis: A dynamic type for Haskell description: Want to do dynamically typed programming in Haskell sometimes? Here you go! homepage: https://github.com/chrisdone/dynamic#readme
src/Dynamic.hs view
@@ -176,6 +176,19 @@ String i -> T.encodeUtf8 i other -> L.toStrict (Aeson.encode other) +instance Semigroup Dynamic where+ Null <> x = x+ x <> Null = x+ Array xs <> Array ys = Array (xs <> ys)+ Dictionary x <> Dictionary y = Dictionary (x <> y)+ String x <> String y = String (x <> y)+ String x <> Double y = String (x <> toText (Double y))+ Double x <> String y = String (toText (Double x) <> y)+ String x <> Bool y = String (x <> toText (Bool y))+ Bool x <> String y = String (toText (Bool x) <> y)+ -- Everything else+ x <> y = String (toText x <> toText y)+ -------------------------------------------------------------------------------- -- Accessors