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 6020049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:30:41+00:00 2026-05-23T03:30:41+00:00

I have a nested, mutual recursive data structure , and want to associate computational

  • 0

I have a nested, mutual recursive data structure, and want to associate computational expensive values to some of the nodes. Actually, I want to temporarily link the Blocks in a Pandoc document to the list of words occuring in that block.

Unattractive options I want to avoid:

  • extending the Block data type such that it includes the word list, which boils down to creating a new extended Pandoc datatype with lots of (fragile) boiler plate code

  • mapping blocks to word lists; which is suboptimal as the blocks are too complex to serve efficiently as keys

The direction I am seeking a solution is some kind of overlay data structure that includes the extended Blocks, but with the underlying data types untouched, so that I can still use the extensive Pandoc libraries. But perhaps this is not the Haskell Way of Thinking…

Post scriptum 2011-06-12:

As the comments show, I probably overestimated the cost of the Map approach, partly based on wrong assumptions. Indeed: “there is nothing more deceptive than an obvious fact”.

Anyway, I accept the answer of hammar, because it illustrates how to create an extensible data type.

Thanks

  • 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-23T03:30:42+00:00Added an answer on May 23, 2026 at 3:30 am

    You can’t add stuff to an existing data type when it was not designed to be extensible, so you’re going to have to rely on some external structure such as a Map to associate the word lists to each block.

    If you could change the datatype however, you could make it extensible by generalizing the recursion in the data type. Let’s say you have a recursive data type like this:

    data Tree = Leaf | Fork String Tree Tree
    

    We can add a parameter for the recursive usage of Tree:

    data GenTree t = Leaf | Fork String t t
    

    Now, to have a plain tree like the original, we take the fixed point of this type:

    data Fix a = Fix (a (Fix a))
    type Tree = Fix GenTree
    

    Now, you can extend the type with additional data at each recursive site. Here’s how to make a type for labelled trees:

    data Labelled t = Labelled Int (GenTree t)
    type LabelledTree = Fix Labelled
    
    strLength :: GenTree t -> Int
    strLength Leaf = 0
    strLength (Fork str _ _) = length str
    
    label :: Tree -> LabelledTree
    label (Fix tree) = Fix $ Labelled (strLength tree) (fmap label tree)
    
    instance Functor GenTree where
        fmap f Leaf = Leaf
        fmap f (Fork s l r) = Fork s (f l) (f r)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some nested tables that I want to hide/show upon a click on
I have a nested movie clip instance that I want to access. The path
I have nested groupboxes, which logically represent nested data structures in my application. Let's
We have nested folders with parent-child relationship. We use MySQL MyISAM DB. The data
I have nested dictionaries: {'key0': {'attrs': {'entity': 'p', 'hash': '34nj3h43b4n3', 'id': '4130'}, u'key1': {'attrs':
I have nested xsl:for loops: <xsl:for-each select=/Root/A> <xsl:for-each select=/Root/B> <!-- Code --> </xsl:for> </xsl:for>
I keep finding that if I have nested divs inside each other, and one
as per the title; is it possible to have nested comments in valid HTML?
I have a nested function to show/hide paragraphs news-ticker-style. The problem is that when
How have you explained nested arrays to a programmer. I'm thinking someone that has

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.