non-injective type families

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE TypeFamilies #-}
module Test where

import Control.Applicative
import Data.Conduit
import Data.Text(Text)
import Data.ByteString.Lazy (ByteString)
import qualified Network.HTTP.Conduit as HTTP
import qualified Network.HTTP.Types as HTTP

class Request a where
    type Parameters a
    genRequest :: Parameters a -> HTTP.Request (ResourceT IO)
    parseResponse :: ByteString -> a

basicReq = undefined

data User = String

instance Request User where
    type Parameters User = Text
    genRequest name = basicReq "users" name

discogs :: Request a => Parameters a -> IO a
discogs params = do
    let req = genRequest params
    resp <- HTTP.withManager $ HTTP.httpLbs req
    return $ parseResponse . HTTP.responseBody $ resp
22:5: Error: Eta reduce
Found:
genRequest name = basicReq "users" name
Why not:
genRequest = basicReq "users"