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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:33:51+00:00 2026-05-23T14:33:51+00:00

I am not very familiar with Map module in Ocaml. I have a simple

  • 0

I am not very familiar with Map module in Ocaml.

I have a simple map m: string Map.Make(Int).t from int to string, and I know that every binding (:string) is unique. I would like to write a funciton find_from_string_to_int: string -> string Map.Make(Int).t -> int, could anyone help? Thank you very much!

  • 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-23T14:33:52+00:00Added an answer on May 23, 2026 at 2:33 pm

    If this is an infrequent operation, the easiest way is to fold over all the (key,value) bindings of the map SMap.fold:

    # module SMap = Map.Make(String);;
    # let reverse v t =
      SMap.fold (fun k v' acc -> if v = v' then Some k else acc) t None;;
    val reverse : 'a -> 'a SMap.t -> SMap.key option = <fun>
    

    If this is a common operation, what you’re looking for is a bidirectional map (a map that can be queried in both “directions”). The easiest way is to carry around a pair of maps: int IMap.t * string SMap.t (accesses in both direction are logarithmic, while the reverse above is linear in the size of the map). You could also implement a dedicated data structure, but that’s probably not worth the added complexity.

    PS: reverse could be optimized to quit the iteration early if the value is found, but if it’s an uncommon operation it’s not really important anyway.

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

Sidebar

Related Questions

I have not used jquery much yet and not very familiar with it. Trying
I'm not very good at C, and I always get stuck on simple string
I'm not very familiar in programming databases, but I have a Mysql-Database which I
I am not very familiar with VB.NET so I don't know if this is
Ok so I'm not very familiar with Jquery as to know the possible cause
I am not very familiar with .htaccess and have already searched through the net
I am not very familiar with the Mac OS X APIs (coming from a
I am really not very familiar with javascript and its syntax, but I have
first i must admit that i'm not very familiar with sql server's recursive CTE's
I am not very familiar with CSS. I have two li elements, each of

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.