Partible: Difference between revisions
(Initial content, loosely based on "Monad") |
mNo edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 6: | Line 6: | ||
<haskell> | <haskell> | ||
module Partible where | |||
class Partible a where | class Partible a where | ||
part :: a -> (a, a) | |||
parts :: a -> [a] | |||
-- Minimal complete definition: part or parts -- | |||
part u = case parts u of u1:u2:_ -> (u1, u2) | |||
parts u = case part u of (u1, u2) -> u1 : parts u2 | |||
</haskell> | </haskell> | ||
In addition to implementing the methods of the class, partible types should satisfy certain equations; for an explanation of them along with why they should be satisfied, see [[Partible laws]]. | In addition to implementing the methods of the class, partible types should satisfy certain equations; for an explanation of them along with why they should be satisfied, see [[Partible laws]]. | ||
[[Category: | [[Category:Research]] |
Latest revision as of 23:11, 29 June 2021
Hint: if you're just looking for an introduction to partible types, see Plainly partible.
The Partible
class
Partible types have an common (and austere) programming interface, this being captured by the Partible
class:
module Partible where
class Partible a where
part :: a -> (a, a)
parts :: a -> [a]
-- Minimal complete definition: part or parts --
part u = case parts u of u1:u2:_ -> (u1, u2)
parts u = case part u of (u1, u2) -> u1 : parts u2
In addition to implementing the methods of the class, partible types should satisfy certain equations; for an explanation of them along with why they should be satisfied, see Partible laws.