[Haskell-cafe] printf using values more than once
Henning Thielemann
lemming at henning-thielemann.de
Fri Jun 4 07:58:21 UTC 2021
On Fri, 4 Jun 2021, Olaf Klinke wrote:
> On Thu, 3 Jun 2021, MigMit wrote:
>
>> At this point I'm not sure how it is different from a simple function. The
>> HoleyMonoid example
>>
>>> holey = now "x = " . later show . now ", y = " . later show
>>
>> when paired with 'argn'-style variables essentially becomes
>>
>>> holey arg1 arg2 = "y = " ++ show arg2 ++ "; x = " ++ show arg1
>>
>> So, what kind of syntax do you have in mind?
>
> What I'm after is documentation of n-ary functions. Suppose
>
> f :: a -> a -> Maybe a
> f arg1 arg2 = if arg1 < arg2 then Nothing else Just arg2
>
> The docstring of f should be a function that, given descriptions of the
> arguments, generates a description of the result. E.g.
>
> doc_f = "if " <> arg1 <> " is smaller than " <> arg2 <> " then Nothing else
> Just " <> arg2
>
> Say you have concrete arguments which are already tagged with a description:
> x :: (String,a)
> y :: (String,a)
>
> One could then have an operator <%> that acts like function application but
> at the same time takes care of documentation:
>
> func desc_f f <%> x <%> y :: (String,c)
>
> Here 'func' is an operator that translates the hypothetical docstring type
> into a real function.
I don't fully understand the problem, but for me it sounds like an
Applicative functor:
data T a = Cons String a
x,y :: T a
func desc_f f <*> x <*> y :: T c
More information about the Haskell-Cafe
mailing list