- The first one is the exploration of category-theoretic concepts and their showing-off in the blogosphere. Generalizations of monads or the category type class are just two recent picks from the bottomless supply of ideas.
- The second trend is more subtle and one has to dive into the recent ICFP papers to perceive it. I have already mentioned the Unimo framework, which guarantees the monad laws and allows to represent the monadic computation as a pure data structure which is then run by recursive analysis. Wouter Swierstra et al. introduced another concept to capture monads (also strongly resembling the free monad) and they have improved testing ability on their minds when doing this. The third paper that comes to my mind is about speeding up arrow computations by analysis and optimization of a data structure closely resembling arrows.

data Thrist :: (* -> * -> *) -> * -> * -> * whereThe definition makes it clear that Thrist is a GADT (I use the Haskell way of defining a GADT here, the paper will use the slightly different Ωmega syntax) and it is a curious mixture of listness and threadedness (this is the reason for its name). The types of the thrist elements must match up in a certain way, resembling function composition.

Nil :: Thrist p a a

Cons :: p a b -> Thrist p b c -> Thrist p a c

Indeed, instead of composing functions, we can put them into a thrist:

Cons ord $ Cons chr Nilgives us an arrow thrist (Thrist (->) Char Char) only showing the start and end types, with the internal types abstracted away existentially.

Of course we have to supply an interpreter for this data structure to get the functionality (the semantics) of function composition, but this easy exercise is left to you.

But... What do thrists buy us?

Two very important things:

- Unlike function composition, we can take the thrist apart, analyse and transform it, and
- a vast field opens up with the first (p) parameter to the Thrist. It can be the pair constructor (,) or the LE (less-or-equal) proposition, there are many sensible instantiations -- especially with two-parameter user-defined GADTs.

I hope you enjoyed reading this in the same way as me writing it!

## 4 comments:

the

Thristtype is declared of kind(* -> * -> *) -> * -> *, which takes two types, but you've passed three types to it in the given types for Nil and Cons. I thinkThristis supposed to have kind(* -> * -> *) -> * -> * -> *.nick, thanks for the clarification, I shall correct this. The error came from *not* wanting to copy&paste the more general definition I have in Ωmega:

data Thrist :: forall (l :: *1) . (l ~> l ~> *) ~> l ~> l ~> * where

Nil :: Thrist k a a

Cons :: k a b -> Thrist k b c -> Thrist k a c

deriving List(l)

In the Haskellifying process one star got dropped :-(

I just noticed that your Thrist type is the same as the FL (forward list) type used by darcs. There the two extra parameters are only used as phantom types, but the definition is otherwise exactly the same. The also define a RL type for reverse lists,

data RL a x z where

(:<:) :: a y z -> RL a x y -> RL a x z

NilRL :: RL a x x

With a reverse function of the type

reverseFL :: FL a x z -> RL a x z

See Darcs.Patch.Ordered for the implementation.

@twan: this is funny, I watched Heffalump's Darcs video the other day, and wanted to ask them if they had a use for thrists! Looks like they are already using them..In my paper I also mention the reverse thrists (corresponding to RL). Unfortunately the paper is under construction 8 months now, and progressing really slowly.

Thanks for the link, I will mention Darcs in the paper.

Post a Comment