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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:51:53+00:00 2026-05-30T10:51:53+00:00

This is a follow up question to this one . I think I misunderstood

  • 0

This is a follow up question to this one. I think I misunderstood a little bit what type is meant to do in Haskell, so here’s, hopefully, a better formulation of the question:

I want to have a function that can be called with exactly two arguments. These arguments must be of different types. For example, one is string, and another is an integer.

Consider this application:

combine "100" 500 -- results in 100500
combine 100 "500" -- results in 100500
combine 100 500 -- raises an exception
combine "100" "500" -- raises an exception

It is not a problem to write a concrete implementation, it is a problem, however, for me, to give this function a proper signature.

I would be also interested to learn whether there is a solution that is more generic (i.e. doesn’t require to specify the concrete types, but only prescribes for the types to be different. So that, for example, you could use this function to “fix” the input to other functions, if it can be fixed by permuting the arguments.

Thank you!

EDIT:

below is an imprecise copy of what I was expecting it to do in Erlang… well, I hope it makes sense, since it should be quite similar…

combine([String], Int)->
    io:fwrite("~s~w~n", [[String], Int]);

combine(Int, [String])->
    combine([String], Int).
  • 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-30T10:51:54+00:00Added an answer on May 30, 2026 at 10:51 am

    Sjoerd beat me to it, but I prefer my solution so I’ll post it anyway.

    {-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances #-}
    
    module Foo where
    
    class Combinable a b where
      combine :: a -> b -> Int
    
    instance Combinable Int String where
      combine a b = read (show a ++ b)
    
    instance Combinable String Int where
      combine a b = read (a ++ show b)
    

    Since this doesn’t include a Combinable a a instance, trying to use one is a compile-time error rather than a runtime error.

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

Sidebar

Related Questions

This is a follow-on question from the one I asked here . Can constraints
This is a follow-up question to this one . Take a look at these
This is like a follow-up question to this one . Basically what I'm doing
I have a follow-up question to this one . I created a new form,
I have a follow up question to this one . Now that I have
This is really a follow on question to a previous one , where I
This question is a follow up on one of my other questions, Can I
This question is a follow on from this one ... I am binding to
Follow-up question to this one . Basically, in the following code, why does the
I am very sorry. This is follow up for my question here : Why

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.