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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:51:44+00:00 2026-05-27T17:51:44+00:00

type node = { lan: string; lat: string; };; let rec read_nodes_from_list list =

  • 0
type node = {
  lan: string;
  lat: string;
};;

let rec read_nodes_from_list list = match list with
  | Xml.Element("node", _, _)::list' -> {lan="A"; lat="B"}::read_nodes_from_list list'
;;

I tried this to create a node record but it doesn’t work. And suppose I have another type that has same attributes of node, how can I tell ocaml which type object to create?

Thank you.

  • 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-27T17:51:45+00:00Added an answer on May 27, 2026 at 5:51 pm

    Obviously, your function didn’t work because you forgot to match with empty list:

    let rec read_nodes_from_list list = match list with
      | Xml.Element("node", _, _)::list' -> {lan="A"; lat="B"}::read_nodes_from_list list'
      | [] -> []
    

    What you’re actually trying to do is a map operation on list, so your function could be written more elegantly as follows:

    let read_nodes_from_list list =
       List.map (fun (Xml.Element("node", _, _)) -> {lan="A"; lat="B"}) list
    

    However, the function may not work because pattern matching on Xml.Element is not exhaustive. You should be careful when handling remaining cases. For example, something like this would work:

    let read_nodes_from_list list =
       List.map (function | (Xml.Element("node", _, _)) -> {lan="A"; lat="B"}
                          | _ -> {lan=""; lat=""}) list
    

    To answer your question about record types, it considers a bad practice to have two record types with the same field label. You still can put these record types in different submodules and distinguish them using module prefixes. But as I said, having two similar record types in the same module causes confusion to you and the OCaml compiler.

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

Sidebar

Related Questions

I am trying to create a new node type like this: http://www.live-wtr.ru/leo/Tikz9.png but don't
Does the CCK api allow me to create a node type, from a custom
I have a content type called fund. The contents of this is in node-fund.tpl.php
Imagine the UI passes back an XMl node as such: <properties> <type> Source </type>
I'm trying to create a node (B type) & assign it to a A
How would you convert type Node into an immutable tree? This class implements a
I have an XML document of store locations which have a Type node indicating
I have list of objects type Node ( items ). And Node class has
module Algorithm where import System.Random import Data.Maybe import Data.List type Atom = String type
this is what i have SELECT node.nid AS nid, node.type AS node_type, product.* FROM

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.