Skip to content

Updates related to psc-0.10 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"package.json"
],
"dependencies": {
"purescript-prelude": "^1.0.1",
"purescript-globals": "^1.0.0",
"purescript-generics": "^1.0.0",
"purescript-maybe": "^1.0.0",
"purescript-strings": "^1.0.0",
"purescript-tuples": "^1.0.0"
"purescript-prelude": "^2.0.0",
"purescript-globals": "^2.0.0",
"purescript-generics": "^3.0.0",
"purescript-maybe": "^2.0.0",
"purescript-strings": "^2.0.0",
"purescript-tuples": "^3.0.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"devDependencies": {
"pulp": "^9.0.0",
"purescript-psa": "^0.3.9",
"purescript": "^0.9.1",
"purescript": "^0.10.1",
"rimraf": "^2.5.0"
}
}
27 changes: 13 additions & 14 deletions src/Data/FormURLEncoded.purs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module Data.FormURLEncoded
( FormURLEncoded()
( FormURLEncoded(FormURLEncoded)
, fromArray
, toArray
, encode
) where

import Prelude (class Show, class Ord, class Eq, map, (<<<), (<>), compare, eq)
import Data.String (joinWith) as String
import Data.Newtype (class Newtype)
import Data.Generic (class Generic)
import Data.Maybe (Maybe(..))
import Data.Monoid (class Monoid)
import Data.Semigroup (class Semigroup)
import Data.String (joinWith) as String
import Data.Tuple (Tuple(..))
import Data.Generic (class Generic, gShow)

import Global (encodeURIComponent)
import Prelude (class Show, class Ord, class Eq, map, (<<<), (<>))

-- | `FormURLEncoded` is an ordered list of key-value pairs with possible duplicates.
newtype FormURLEncoded
Expand All @@ -27,15 +29,12 @@ toArray :: FormURLEncoded -> Array (Tuple String (Maybe String))
toArray (FormURLEncoded a) = a
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be replaced with a Newtype instance now.

Copy link
Contributor Author

@zudov zudov Oct 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a Newtype instance, but still have monophonic functions.

I think Newtype is very nice with it's higher-order combinators (e.g. over MyNewType f vs MyNewtype <<< f <<< runNewType), and possibility for abstracting over newtypes (e.g. StrMap with polymorphic functions forall key. Newtype key String).

However for simple construction/deconstruction I think I'll often be preferring plain functions:

  • they make mistakes more wrong looking, in order to construct/deconstruct a type you have to somehow mention it's name, either directly in a function name (runNewtype) or through qualified import (MyNewType.fromArray).
  • they are more interference-friendly (serialize $ MyNewType.fromArray [...] vs serialize (wrap [ ... ] :: MyNewType) where serialize :: Serializable a => a -> String.


derive instance genericFormUrlEncoded :: Generic FormURLEncoded

instance eqFormUrlEncoded :: Eq FormURLEncoded where
eq (FormURLEncoded a) (FormURLEncoded b) = eq a b

instance ordFormUrlEncoded :: Ord FormURLEncoded where
compare (FormURLEncoded a) (FormURLEncoded b) = compare a b

instance showFormUrlEncoded :: Show FormURLEncoded where
show = gShow
derive instance newtypeFormUrlEncoded :: Newtype FormURLEncoded _
derive newtype instance eqFormUrlEncoded :: Eq FormURLEncoded
derive newtype instance ordFormUrlEncoded :: Ord FormURLEncoded
derive newtype instance showFormUrlEncoded :: Show FormURLEncoded
derive newtype instance semigroupFormUrlEncoded :: Semigroup FormURLEncoded
derive newtype instance monoidFormUrlEncoded :: Monoid FormURLEncoded

-- | Encode `FormURLEncoded` as `application/x-www-form-urlencoded`.
encode :: FormURLEncoded -> String
Expand Down