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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:16:32+00:00 2026-06-17T19:16:32+00:00

I need to create a dictionary in sml, but I am having extreme difficulty

  • 0

I need to create a dictionary in sml, but I am having extreme difficulty with an insert function.

    type dict = string -> int option

As an example, here is the empty dictionary:

    val empty : dict = fn key => NONE

Here is my implementation of an insert function:

    fun insert (key,value) d = fn d => fn key => value

But this is of the wrong type, what I need is insert : (string*int) -> dict -> dict.
I’ve searched everything from lazy functions to implementing dictionaries.
Any help or direction would be greatly appreciateds!

If you are still confused on what I am trying to implement, I drafted up what I should expect to get when calling a simple lookup function

    fun lookup k d = d k

    - val d = insert ("foo",2) (insert ("bar",3) empty);
    val d = fn : string -> int option
    - lookup2 "foo" d;
    val it = SOME 2 : int option
    - lookup2 "bar" d;
    val it = SOME 3 : int option
    - lookup2 "baz" d;
    val it = NONE : int option
  • 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-17T19:16:33+00:00Added an answer on June 17, 2026 at 7:16 pm

    You can reason on the signature of the function:

    val insert = fn: (string * int) -> dict -> dict
    

    When you supply key, value and a dictionary d, you would like to get back a new dictionary d'. Since dict is string -> int option, d' is a function takes a string and returns an int option.

    Suppose you supply a string s to that function. There are two cases which could happen: when s is the same as key you return the associated value, otherwise you return a value by looking up d with key s.

    Here is a literal translation:

    fun insert (key, value) d = fn s => if s = key then SOME value
                                        else d s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a Dictionary object as a member field key = string
I need to create an dictionary by splitting a string like this: [SenderName] Some
I need to create a list like List<String,Object> but I can't seem to do
I need create clone repository. but I do not know where can I get
I have a dictionary. I need to create buttons with keys name, and clicked
I need to create a dictionary/hashmap where the Keys are enums Values are some
I need to create a dictinary where key is string and value is Object.
I need to create container like this: Container.Add(RowIndex, ValueIndex); I know Dictionary just have
I need to create a Tree of words with the class Dictionary in as3.
I need simple linq Query which will create Dictionary I have Xml which contains

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.