Hi Chris,
I don't think you're missing anything in 'servant' itself. But perhaps Oleg
Kiselyov's 'mcomp' [0] is of help. The new 'routeToText' would just be:
> renderURI `mcomp` routeToURI
I don't think anyone has packaged 'mcomp' yet. For your use case there is, I
think, only one base case (URI), so it'd in all be something like:
--
You received this message because you are subscribed to the Google Groups "haskell-servant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-servant+unsubscribe@googlegroups.com.
To post to this group, send email to haskell-servant@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-servant/CAHZ8tnY%3D47YSOoPmSTkjqYYs53wjnR%3DWY_U231qDOvTYWDP8fA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-servant/CADnndOq2VuR5Zg6kfV8GPABCZE3VrXv4VA1KNR8kX4mSt5A7Vw%40mail.gmail.com.
Here are the two messages exchanged outside of the haskell-servant usergroup. My fault for accidentally not CCing the group.---------- Forwarded message ----------
From: Christopher Allen <c...@bitemyapp.com>
Date: Thu, Oct 20, 2016 at 9:40 PM
Subject: Re: Lifting Capture param requirements when getting Text-ified Route
To: Julian Arni <jka...@turingjump.com>
Finally got it working, the difference was my version wasn't static -
depends on the App monad.
routeToText :: ( IsElem a Routes
, HasLink a
, MCompose () (MkLink a) URI (App Text) (() -> w)
)
=> Proxy a
-> w
routeToText p = go ()
where go = (\() -> routeToURI p) `mcomp` renderURI
This now compiles:
articleListing :: Article -> App Html
articleListing a@Article{..} = do
postUri <- routeToText proxyGetPostR (articleSlug a)
Thank you very much!
On Tue, Oct 18, 2016 at 11:41 AM, Julian Arni <jka...@turingjump.com> wrote:
> Probably because I got the composition order wrong (mcomp flips .). There's
> also a little dance with the case of no arguments that I hadn't thought about.
>
> Here's some code, this time actually tested:
>
>> {-# LANGUAGE DataKinds #-}
>> {-# LANGUAGE MultiParamTypeClasses #-}
>> {-# LANGUAGE FunctionalDependencies #-}
>> {-# LANGUAGE FlexibleInstances #-}
>> {-# LANGUAGE FlexibleContexts #-}
>> {-# LANGUAGE GADTs #-}
>> {-# LANGUAGE TypeOperators #-}
>> {-# LANGUAGE UndecidableInstances #-}
>> import Servant
>>
>> routeToURI :: (IsElem a MyAPI, HasLink a) => Proxy a -> MkLink a
>> routeToURI = safeLink (Proxy :: Proxy MyAPI)
>>
>>
>> type Ep1 = "static" :> Get '[JSON] Int
>> type Ep2 = Capture "" Int :> Ep1
>> type Ep3 = Capture "" String :> Capture "" Int :> Ep1
>> type MyAPI = Ep1 :<|> Ep2 :<|> Ep3
>>
>> routeToText ::
>> (IsElem a MyAPI, HasLink a, MCompose () (MkLink a) URI String (() -> w))
>> => Proxy a
>> -> w
>> routeToText p = go ()
>> where go = (\() -> routeToURI p) `mcomp` renderURI
>>
>> renderURI :: URI -> String
>> renderURI = show
>>
>>
>> class MCompose f1 f2 cp gresult result | f1 f2 cp gresult -> result, f2->cp where
>> mcomp:: (f1->f2) -> (cp->gresult) -> result
>>
>> instance (MCompose f1 f2 cp gresult result) =>
>> MCompose a (f1->f2) cp gresult (a->result) where
>> mcomp f g = \a -> mcomp (f a) g
>>
>> instance MCompose a URI URI c (a->c) where
>> mcomp f g = g . f
>>
>> main :: IO ()
>> main = do
>> putStrLn $ routeToText (Proxy :: Proxy Ep1)
>> putStrLn $ routeToText (Proxy :: Proxy Ep2) 5
>> putStrLn $ routeToText (Proxy :: Proxy Ep3) "neat" 5
>> To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-servant/CADnndOq2VuR5Zg6kfV8GPABCZE3VrXv4VA1KNR8kX4mSt5A7Vw%40mail.gmail.com.
> --