Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6923479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:32:27+00:00 2026-05-27T10:32:27+00:00

Yesterday’s Wikibender that started with this stackoverflow qestion on Comonads ended up at MarkCC’s

  • 0

Yesterday’s Wikibender that started with this stackoverflow qestion on Comonads ended up at MarkCC’s article on Finger Trees.

In the article he makes extensive use of the Reduce type class. He writes about this typeclass as if it is a very common and frequently use library, but I cannot find it on hackage, nor can I find enough documentation to really understand the code.

Can someone help me understand what the Reduce typeclass is doing, how the (-<) and (>-) operators work, and what should tell me about the code in the article (copied below)?


Code Listing from Finger Trees Done Right (I hope):

Listing 1: instance declaration for Node

instance Reduce Node where
  reducer (-<) (Node2 a b) z = a -< (b -< z)
  reducer (-<) (Node3 a b c) z = a -< (b -< (c -< z))
  reducer (>-) (Node2 b a) = (z >- b) >- a
  reducer (>-) (Node3 c b a) = ((z >- c) >- b) >- a

Listing 2: instance declaration for FingerTree

instance Reduce FingerTree where
  reducer (-<) Empty zero = zero
  reducer (-<) (Single x) zero = x -< zero
  reducer (-<) Deep left mid right zero = left -<' (mid -<'' (right -<' zero))
    where (-<') = reducer (-<)
          (-<'') = reducer (reducer (-<))
  reducel (>-) zero Empty = zero
  reducel (>-) zero (Single x) = zero >- x
  reducel (>-) zero (Deep left mid right) = ((zero >-' left) >-'' mid) >-' right
    where (>-') = reducel (>-)
          (>-'') = reducel (reducel (>-))

listing 3: data types

data Node s = Node2 s s | Node3 s s s

data FingerTree a = Empty
  |  Single a
  | Deep (Digit a) (FingerTree (Node a)) (Digit a)

data Digit a = [ a ]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:32:28+00:00Added an answer on May 27, 2026 at 10:32 am

    Given that reduce is a common alternate name for a “fold” function, I’d guess that it’s something similar to the Foldable type class. The instance definitions seem to make sense as such, as well.

    The Foldable class can be defined using just foldr, which has the type signature foldr :: (Foldable t) => (a -> b -> b) -> b -> t a -> b, whereas the reducer in that code appears to be reducer :: (Reduce t) => (a -> b -> b) -> t a -> b -> b. Other than a different argument order, it should work the same.

    Note that the operators are just arguments to the function–you could replace them all with f or another similarly generic identifier. Using an operator as the name of a binary function argument is… a slightly unusual choice, but it does emphasize some aspects of the structure of the fold, I guess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I created this piece of code that could calculate z^n, where z is
Yesterday, I asked this question and never really got an answer I was really
Yesterday, I discovered the Subversion (SVN) blame feature, and I was wondering, is this
Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
Yesterday I found this function: function clone(obj) { return typeof obj === 'undefined' ?
Yesterday, my supervisor told me that tmp-file-based session should be THE answer to session
Yesterday I felt in big issue that happens with all my projects. After I
yesterday i noticed that sometimes on my webpage shows up javascript errors. when i
Yesterday i tried to create an object for this class to be able to
Yesterday I discovered an odd bug in rather simple code that basically gets text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.