Skip to content

Commit bd8e6b8

Browse files
committed
Merge pull request #22 from slamdata/phantom-responsetype
Use phantom type instead of Proxy for ResponseType
2 parents c7b24ce + fdc0ec2 commit bd8e6b8

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

Diff for: bower.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"purescript-dom": "~0.1.2",
2525
"purescript-foreign": "~0.4.2",
2626
"purescript-integers": "~0.0.1",
27-
"purescript-nullable": "~0.1.1",
28-
"purescript-proxy": "~0.1.0"
27+
"purescript-nullable": "~0.1.1"
2928
}
3029
}

Diff for: docs/Network.HTTP.Affjax.Response.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@
55
#### `ResponseType`
66

77
``` purescript
8-
data ResponseType
8+
data ResponseType a
99
```
1010

1111
Valid response types for an AJAX request. This is used to determine the
12-
`ResponseContent` type for a request.
12+
`ResponseContent` type for a request. The `a` type variable is a phantom
13+
type used to associate the `ResponseType` with a particular instance of
14+
`Respondable`.
1315

1416
#### `eqResponseType`
1517

1618
``` purescript
17-
instance eqResponseType :: Eq ResponseType
19+
instance eqResponseType :: Eq (ResponseType a)
1820
```
1921

2022

2123
#### `showResponseType`
2224

2325
``` purescript
24-
instance showResponseType :: Show ResponseType
26+
instance showResponseType :: Show (ResponseType a)
2527
```
2628

2729

2830
#### `responseTypeToString`
2931

3032
``` purescript
31-
responseTypeToString :: ResponseType -> String
33+
responseTypeToString :: forall a. ResponseType a -> String
3234
```
3335

3436

@@ -45,7 +47,7 @@ Type representing content types that be received from an XHR request
4547

4648
``` purescript
4749
class Respondable a where
48-
responseType :: Proxy a -> ResponseType
50+
responseType :: ResponseType a
4951
fromResponse :: ResponseContent -> F a
5052
```
5153

Diff for: src/Network/HTTP/Affjax.purs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import Network.HTTP.Method (Method(..), methodToString)
2727
import Network.HTTP.RequestHeader (RequestHeader(), requestHeaderName, requestHeaderValue)
2828
import Network.HTTP.ResponseHeader (ResponseHeader(), responseHeader)
2929
import Network.HTTP.StatusCode (StatusCode())
30-
import Type.Proxy (Proxy(..))
3130

3231
-- | The effect type for AJAX requests made with Affjax.
3332
foreign import data AJAX :: !
@@ -130,7 +129,7 @@ affjax' req eb cb =
130129
, url: req.url
131130
, headers: (\h -> { field: requestHeaderName h, value: requestHeaderValue h }) <$> req.headers
132131
, content: toNullable (toRequest <$> req.content)
133-
, responseType: responseTypeToString $ responseType (Proxy :: Proxy b)
132+
, responseType: responseTypeToString (responseType :: ResponseType b)
134133
, username: toNullable req.username
135134
, password: toNullable req.password
136135
}

Diff for: src/Network/HTTP/Affjax/Response.purs

+13-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ import Type.Proxy (Proxy())
1414
import qualified Data.ArrayBuffer.Types as A
1515

1616
-- | Valid response types for an AJAX request. This is used to determine the
17-
-- | `ResponseContent` type for a request.
18-
data ResponseType
17+
-- | `ResponseContent` type for a request. The `a` type variable is a phantom
18+
-- | type used to associate the `ResponseType` with a particular instance of
19+
-- | `Respondable`.
20+
data ResponseType a
1921
= ArrayBufferResponse
2022
| BlobResponse
2123
| DocumentResponse
2224
| JSONResponse
2325
| StringResponse
2426

25-
instance eqResponseType :: Eq ResponseType where
27+
instance eqResponseType :: Eq (ResponseType a) where
2628
(==) ArrayBufferResponse ArrayBufferResponse = true
2729
(==) BlobResponse BlobResponse = true
2830
(==) DocumentResponse DocumentResponse = true
@@ -31,14 +33,14 @@ instance eqResponseType :: Eq ResponseType where
3133
(==) _ _ = false
3234
(/=) x y = not (x == y)
3335

34-
instance showResponseType :: Show ResponseType where
36+
instance showResponseType :: Show (ResponseType a) where
3537
show ArrayBufferResponse = "ArrayBufferResponse"
3638
show BlobResponse = "BlobResponse"
3739
show DocumentResponse = "DocumentResponse"
3840
show JSONResponse = "JSONResponse"
3941
show StringResponse = "StringResponse"
4042

41-
responseTypeToString :: ResponseType -> String
43+
responseTypeToString :: forall a. (ResponseType a) -> String
4244
responseTypeToString ArrayBufferResponse = "arraybuffer"
4345
responseTypeToString BlobResponse = "blob"
4446
responseTypeToString DocumentResponse = "document"
@@ -50,25 +52,25 @@ responseTypeToString StringResponse = "text"
5052
type ResponseContent = Foreign
5153

5254
class Respondable a where
53-
responseType :: Proxy a -> ResponseType
55+
responseType :: ResponseType a
5456
fromResponse :: ResponseContent -> F a
5557

5658
instance responsableBlob :: Respondable Blob where
57-
responseType _ = BlobResponse
59+
responseType = BlobResponse
5860
fromResponse = unsafeReadTagged "Blob"
5961

6062
instance responsableDocument :: Respondable Document where
61-
responseType _ = DocumentResponse
63+
responseType = DocumentResponse
6264
fromResponse = unsafeReadTagged "Document"
6365

6466
instance responsableJSON :: Respondable Foreign where
65-
responseType _ = JSONResponse
67+
responseType = JSONResponse
6668
fromResponse = Right
6769

6870
instance responsableString :: Respondable String where
69-
responseType _ = StringResponse
71+
responseType = StringResponse
7072
fromResponse = readString
7173

7274
instance responsableUnit :: Respondable Unit where
73-
responseType _ = StringResponse
75+
responseType = StringResponse
7476
fromResponse = const (Right unit)

0 commit comments

Comments
 (0)