[Haskell-cafe] Specialize a function on types of arguments?

Anthony Clayden anthony_clayden at clear.net.nz
Tue Nov 20 03:03:25 UTC 2018

On Mon, 19 Nov 2018 at 21:03, Olaf Klinke wrote:

>>* The top-level story is that I am trying to create a monad that somehow*
*>*>* records the "intermediate steps" of computation.*

> If it is only for knowing where things went wrong, ...

Thanks Olaf, no I think Ducis wants to stack the whole history of the

> If ... Then you need to stack a state transformer on top,

Yes a monad transformer might be it. Thank you for the example.

As per my previous message, I'm not convinced it needs monads at all.
Here's a dumb approach as a straw man, showing that type-changing
steps are nothing special (or perhaps I mean type-preserving steps are
nothing special ;-). Ducis could explain why this won't do

nil = ()

cons x l = (x, l)

start :: a -> (a,())

start x = cons x nil            -- i.e. singleton x

infixl 0 $>>

($>>) :: (b, _a) -> (b -> c) -> (c, (b, _a))

xs@(x, z) $>> f = cons (f x) xs

eg = start 1 $>> (+ 1) $>> (+ 3) $>> double $>> show

===> ("10",(10,(5,(2,(1,())))))

I chose ($>>) to be similar to ($>) from the Control.FPipe package
"trivial F#-style pipes for function composition and application".

You could use Datakind `'[]` instead of the 'poor man's heterogeneous
list' I've used, but that seems over-engineering.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181120/55288356/attachment.html>

More information about the Haskell-Cafe mailing list