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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:03:20+00:00 2026-05-31T03:03:20+00:00

I try to put a branching diagram into lists and sublists layout is msg01

  • 0

I try to put a branching diagram into lists and sublists
layout is

  • msg01
  • msg02
    • msg03
    • msg04
  • msg05

And i want to walk the branching diagram top -> bottom going into each branch
but it fails with

Error Type mismatch. Expecting a ('a * 'b list) list but given a 'b list The resulting type would be infinite when unifying ‘'a‘ and ‘'b * 'a list‘

Can anybody gives me some ideas what could fix this?

open System

let msgDiagram1 = [ ("msg03",[]); ("msg04",[]) ]
let msgDiagram = [ ("msg01", []); ("msg02", msgDiagram1); ("msg05",[]) ]      

let listToString lst =
    let rec loop acc = function
        | []    -> acc
        | x::xs -> let node = x
                   let sublst = snd(node)                      
                   if not ( sublst = List.empty ) then                        
                        loop "" sublst
                   else 
                        loop (acc + (string x)) xs

    loop "" lst

printfn "%A" (listToString msgDiagram)
  • 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-31T03:03:21+00:00Added an answer on May 31, 2026 at 3:03 am

    Since msgDiagram1 and msgDiagram have different types, you cannot use the same loop function on them. One quick fix is to process differently on msgDiagram1:

    let listToString lst =
        let rec loop acc = function
            | [] -> acc
            | (lbl, diag)::xs ->
                match diag with
                | [] -> loop (acc + string lbl + "\n") xs
                | _ ->
                    let s = diag |> List.map (fun (label, _) -> "..." + label) 
                                 |> String.concat "\n"
                    loop (acc + string lbl + "\n" + s + "\n") xs
        loop "" lst
    

    You chose a wrong data structure for the job; therefore, you cannot represent more than 2 levels of diagrams and these levels are forced to have different types. The right tool to use here is recursive tree data structure:

    type Diagram = Branch of string * Diagram list
    

    Now above values can be defined using the same type Diagram list:

    let msgDiagram1 = [ Branch ("msg03",[]); Branch ("msg04", []) ]
    let msgDiagram = [ Branch ("msg01", []); Branch ("msg02", msgDiagram1); 
                       Branch ("msg05", []) ]
    

    and listToString can be rewritten to process Diagram list recursively in one batch.

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

Sidebar

Related Questions

When I try to put a value into a DATE field which is invalid,
As I try to put UIImage into a UIImageView, UIImageView auto-expended to display real
When I try to put some condition value into ContentValues variable, there is inserting
So,here's my problem. When i try to put icons into resources and then select
I'm new to XML. When I try put in some cases into it's XML-parent
in my webapp for iPhone/Android/BB6 I try to put all the images into image
So, I really want to try and put numbers near my ImageButtons (kinda like
If I try to put a string into a Boolean variable such as this:
I try to put the value of lastPointX into a label text, but doesn't
When I try to put my weather widget on the homescreen I want to

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.