logo
首页技术栈工具库讨论
Cascade

Cascade

[Index] For package maintainers and hackage trustees <b>Cascade</b>s are collections of composable functions (e.g. a -> b, b -> c, ... , y -> z) where the intermediate types are stored in a type level list (e.g. Cascade [a,b,c,...,y,z]). For example, consider these Cascades: We can convert a cascade into a function easily enough: But that's not very inspiring. The real question, as Christian Conkle put it, is "what does such a collection give you over function composition?" Because none of the type information has been lost, we can still extract each of the functions that went into the Cascade using simple pattern matching. This opens the door to replacing parts of a cascade, or indexing into the cascade with type-level naturals. It also lets us do something silly like mix and match two different cascades: More seriously, we can record the intermediate results of each Cascade using a Product type as output: Or I can resume the computation at some later point rather that the first function in the Cascade using a Sum type as input: Or we could do both: But what's nice is that this generalizes nicely to categorical composition, so we can do the same with any category, including the Kleisli and Cokleisli categories for Monads and Comonads, respectively: Flipping back to ghci: resume works on both comonads and monads: record works on comonads, but I've been having some issues getting it to work the way I want on monads (see Cascade.Product.hs for more). So, instead of continue to wrestle the type system, for now, I just implemented a debugger that uses Cascades, so in addition running a monadic Cascade you can debug it. Dropping into ghci: We can see the current state of the debugger: the full stack trace back up, step forward: (Note that when we step forward, the monadic computation reruns) We can also use a different input than the default at the current stage: And since the debuggers are normal immutable haskell values, we can use both d and d' without errors. Cascades are still very limited. They're linear, and of a set length. They don't let you hook into functions that call themselves recursively, or functions that have computation paths better represented by trees or lattices. But that doesn't mean those are necessarily impossible to model, either. For example, simple recursion is fairly easily captured with only a slight modification to Cascade
由 
bruceshi2021-01-13 收录
--
推荐
不推荐
更多信息
GitHub iconrampion/Cascade15
HACKAGE
carbal install Cascade
查看
标签
根据用户添加的标签生成
暂无标签