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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:50:49+00:00 2026-06-01T13:50:49+00:00

What I really want to do is iterate over the keys of a stringmap.

  • 0

What I really want to do is iterate over the keys of a stringmap. I am using the new-fangled syntax. I can’t find any info on StringMap.iter() so I used the syntax I found somewhere for List.iter(). I don’t think the original code actually iterated over the keys, and for now I would settle for iterating over the values if I could get that to work.

The code I have is here:
http://pastebin.com/9HB20yzy

I get the following error:

Error
File "test.opa", line 23, characters 1-64, (23:1-23:64 | 472-535)
Function was found of type
(string, 'a -> void), ordered_map(string, 'a, String.order) -> void but
application expects it to be of type
(string -> xhtml), stringmap(item) -> 'b.
Types string, 'a -> void and string -> xhtml are not compatible
Hint:
  Function types have different arguments arity (2 versus 1).

I tried several other methods, but they appeared to be using the old syntax and didn’t jive with the compiler. I don’t really understand what this error voodoo is telling me, so the question is, how does one use StringMap.iter()? Or iterate over the keys in a StringMap in some other way?

  • 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-01T13:50:50+00:00Added an answer on June 1, 2026 at 1:50 pm

    Function types have different arguments arity (2 versus 1) means you try to use a function taking 1 argument, whereas a function with 2 arguments is expected. You iterate on a list through values only, but you iterate on a map through keys and values.

    Then, List.iter or StringMap.iter are mean’t to perform side effect (like logging in the console for example). They return no value. This is probably not what you want to do in your code.

    You should use StringMap.fold instead:

    // item is a record of type {string description, string url}
    function render_item(item) {
    <>
      <li>
        <h4>item</h4>
        <a href="{item.url}">{item.description}</a>
      </li>
    </>
    }
    
    function render_index() {
        function f(key, item, acc){
            [render_item(item) | acc]
        }
        <ul>
          { StringMap.fold(f, /mydb/items, []) }
        </ul>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really new to python and I can't find any information about this.
I want to iterate over an ArrayCollection in Flex while there can be items
I want to iterate over really many files which are placed in a deep
I really want to know your experience at working with ADO.Net datasets (calling stored
I really want to have a column of inifinite length for one of the
I really want Resharper to format my line-wrapped ternaries in this way return navigator.IsTerminating
I'm a PHP programmer and I really want to increase the quality of my
I know about the ADODB.Stream object . But what I really want is a
Is there a way to dynamically create a selectItem list? I dont really want
Preferably with visual illustrations... MSDN just lists class-names and what I really 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.