Suppose we wish to convert a number to its base \( b \) representation. GMP uses arrays of limbs to represent large integers; we need to tease out its base \( 2 ^{64} \) representation.
This can be accomplished with a co-(Elgot algebra) as follows:
import Data.Functor.Foldable
import Data.Word
integerToWordList :: Integer -> [Word64]
integerToWordList = coelgot pa c where
c i = Cons (fromIntegral (i `mod` (2 ^ (64 :: Int)))) (i `div` (2 ^ (64 :: Int)))
pa (i, ws) | i < 2 ^ (64 :: Int) = [fromIntegral i]
| otherwise = embed ws
This does not entirely justify the added complexity, but the example is nonetheless instructive.
The implementation in the (deprecated) gmpint package is in fact the only example of a co-(Elgot algebra) on the entirety of Hackage!