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

  • SEARCH
  • Home
  • 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 9256825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:03:37+00:00 2026-06-18T12:03:37+00:00

I have a deeply nested record which I am trying to rebuild from the

  • 0

I have a deeply nested record which I am trying to rebuild from the database. For example, A contains many B records. B records have many C records. C has many Ds. I have functions to query the children of each type of object (f0, f1, and f2 below).

f0 :: A -> [B]
f1 :: B -> [C]
f2 :: C -> [D]

I am looking for an elegant way to implement f3.

f3 :: A -> (A, [(B, [(C, [D])])])

I’ve read a little bit on Arrows and it feels like they might be a good fit. However, I keep hitting a road block when I try to combine them.

I’ve started with something like this:

f4 :: A -> (A, [B])
f4 = id &&& f0

which gets me to the first level. However, I’m at a loss to find a way to chain that to another arrow which would map [B], return [(B, [C])]and use that as the second element of the original tuple.

I’m a bit new to Haskell, so please let me know if I need to include any additional information.

Thanks!

Update

Modifying sclv’s answer slightly, I now have

data A = A
data B = B
data C = C
data D = D

f0 :: A -> [B]
f0 = undefined

f1 :: B -> [C]
f1  = undefined

f2 :: C -> [D]
f2 = undefined

pairFun f = id &&& f

foo :: A -> (A, [(B, [C])])
foo = fmap (map (pairFun f1)) . pairFun f0

I still can’t wrap my mind around how to combine the last function (f2).

Final update

Thanks to sclv, it turns out this can be done like this:

foo = (fmap . map) ((fmap . map) (pairFun f2) . pairFun f1) . pairFun f0
  • 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-06-18T12:03:38+00:00Added an answer on June 18, 2026 at 12:03 pm

    something like this should work (untested):

    pairFun f = id &&& f
    
    foo = (fmap . map) ((fmap . map) (pairFun f2) . pairFun f1) . pairFun f0
    

    edit: one way to think about this, by the way, is using conal’s model of semantic editor combinators — http://conal.net/blog/posts/semantic-editor-combinators

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

Sidebar

Related Questions

I have 3 Deeply nested attraibutes: Process has many categories , Categories has many
I have a page with deeply-nested HTML elements generated from a framework. I would
If I have a deeply-nested model graph, coming from the server (a lot of
I have a deeply nested for-comprehension, simplified to 3 levels below: x, y, and
I have some deeply randomly nested dictionary as follows. {'CompilationStatistics': {'CodeGeneration': {'EndTime': '2010-04-21T14:03:11', 'StartTime':
Suppose we have to use in some function deeply nested pointer very extensively: function
I have a nested unordered list representing a tree hierarchy. There can be many
I have this deeply nested list (list of lists) and I want to replace
I have a deeply nested partial view, where I iterate over a collection of
I have a several nested methods in my program. If a deeply nested method

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.