logo
down
shadow

Histomorphism a la Mendler


Histomorphism a la Mendler

By : Wang Longbiao
Date : November 27 2020, 01:01 AM
this one helps. Using a histomorphism (histo) from recursion-schemes I can get the a list containing only the odd indexes from an initial list: , This is it:
code :
modds :: Fix (ListF a) -> [a]
modds = mhisto alg
    where
    alg _ _ Nil = []
    alg odd pre (Cons a b) = a : case pre b of
        Nil -> []
        Cons _ b' -> odd b' 
GHCi> list = cata embed [1..10] :: Fix (ListF Int)
GHCi> odds (cata embed list)
[1,3,5,7,9]
GHCi> modds list
[1,3,5,7,9]
cata  :: Functor f => (f c -> c) -> Fix f -> c
histo :: Functor f => (f (Cofree f c) -> c) -> Fix f -> c

mcata  :: (forall y. (y -> c) -> f y -> c) -> Fix f -> c
mhisto :: (forall y. (y -> c) -> (y -> f y) -> f y -> c) -> Fix f -> c 


Share : facebook icon twitter icon
Related Posts Related Posts :
  • What are the pitfalls of using FlexibleContexts and FlexibleInstances?
  • Haskell Shelly sample code
  • Finding type signatures in Haskell that are too specific
  • haskell - will pattern matching work faster for non-specific form of an algebraic data type?
  • Cannot enter multiline statements in GHCi
  • Using Gloss to run a simulation while using SDL to play a sound
  • Haskell - Calculating the shortest path using trees
  • Beginner: Converting Types in Haskell
  • G-machine, (non-)strict contexts - why case expressions need special treatment
  • Indentation with Let Statements
  • Haskell parse list of integers with Attoparsec
  • Change (0, 1] to (0, 1) without branching
  • Haskell equivalent to contains
  • Is there a way to unmap in Haskell?
  • Using HLint.hs file in EclipseFP
  • Don't know how to use . and $ operator in Haskell
  • Why is my haskell code so slow
  • How is FRP handled in terms of memory?
  • Generalizing traversal of expressions with changes on specific nodes
  • Why does pattern matching on this GADT seem to introduce ambiguity in the type checker?
  • How to detect end of input with pipes
  • Basic Haskell IO Monad FilePath join
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org