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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:39:06+00:00 2026-05-24T09:39:06+00:00

I have a record in a document that use two IntMaps: data Doc =

  • 0

I have a record in a document that use two IntMaps:

data Doc = Doc { kernels :: IntMap Kernel, nodes :: IntMap Node }

But I found that the keys from both IntMaps have different meaning and I fail to separate in two differents types and don’t get errors when mix kernel types and node types. I want to have functions that check the the keys from kernel map and node maps and don’t allow mix-up. E.g:

someFunction :: Doc -> KernelKey -> NodeKey -> a
someFunction doc k1 k2 = .....

Instead of current:

someFunction :: Doc -> Int -> Int -> a
someFunction doc k1 k2 = .... -- warning check twice k1 and k2

Is it posible? Or I shall change from IntMap to Map.

Thanks

  • 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-24T09:39:07+00:00Added an answer on May 24, 2026 at 9:39 am

    You can use newtype to make wrappers around Int to distinguish their meaning.

    newtype KernelKey = KernelKey Int
    newtype NodeKey = NodeKey Int
    
    someFunction :: Doc -> KernelKey -> NodeKey -> a
    someFunction doc (KernelKey k1) (NodeKey k2) = ...
    

    That way, you can still use IntMap internally, but expose a more type-safe interface, especially if you also control how the KernelKey and NodeKey values get created, i.e. you don’t export their constructors so users only get them as return values from your other functions.

    Note that newtype wrappers disappear at run time, so this extra wrapping and unwrapping does not affect performance in any way.

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

Sidebar

Related Questions

I have a large xml document that needs to be processed 100 records at
I have an XML document which looks something like this: <meadinkent> <record> <comp_div>MENSWEAR</comp_div> <sty_ret_type>ACCESSORIES</sty_ret_type>
I have a record set that includes a date field, and want to determine
Let's say that I have a record in the database and that both admin
I have a master record which I'd like to use with. Here's a very
I'm thinking about trying MongoDB to use for storing our stats but have some
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
We have an architecture where we use SSIS to extract data from XML batch
I have sortable objects that I need to record the ID of the .next()
Alright, I have some data that I need to assign an int type identifier

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.