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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:09:23+00:00 2026-06-17T21:09:23+00:00

Below the code from here Fun with Type Functions {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts,

  • 0

Below the code from here Fun with Type Functions

{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, TypeFamilies #-}

-- Start basic
class Add a b where
  type SumTy a b
  add :: a -> b -> SumTy a b

instance Add Integer Double where
  type SumTy Integer Double = Double
  add x y = fromIntegral x + y

instance Add Double Integer where
  type SumTy Double Integer = Double
  add x y = x + fromIntegral y

instance (Num a) => Add a a where
  type SumTy a a = a
  add x y = x + y
-- End basic

This is the code which I’m trying to run:

main = print $ show (add 1 1)

This is the result:

No instance for (Show (SumTy a0 b0))
      arising from a use of `show'
    Possible fix: add an instance declaration for (Show (SumTy a0 b0))
    In the second argument of `($)', namely `show (add 1 1)'
    In the expression: print $ show (add 1 1)
    In an equation for `main': main = print $ show (add 1 1)

I’ve tried few things like putting “data” everywhere:

Result 1

Not a data constructor: `a'

Result 2 (after removing “instance (Num a)”)

Multiple declarations of `Double'
Declared at: ...

like adding some function:

class Add a b where
    type SumTy a b
    add :: a -> b -> SumTy a b
    s :: SumTy a b -> String

instance Add Integer Double where
    type SumTy Integer Double = Double
    add x y = fromIntegral x + y
    s (SumTy _ x) = show x

main = print $ show (s (add 1 2.0) )

with this result:

Not in scope: data constructor `SumTy'

As you may have noticed I’m stuck so any help is priceless for me. 🙂

  • 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-17T21:09:24+00:00Added an answer on June 17, 2026 at 9:09 pm

    The problem is that there is not enough context to determine which instance of Add to use, and hence the type of the result cannot be determined. Since ghc doesn’t know which types to use, it reports the most generic problem, there’s no Show instance for a generic SumTy a b:

    No instance for (Show (SumTy a0 b0))
          arising from a use of `show'
        Possible fix: add an instance declaration for (Show (SumTy a0 b0))
        In the second argument of `($)', namely `show (add 1 1)'
        In the expression: print $ show (add 1 1)
        In an equation for `main': main = print $ show (add 1 1)
    

    The suggested “Possible fix” isn’t what is required here, though. What you need is to specify the types of the arguments to add, so that the instance to use can be determined, and thus the result type:

    *TyFun> show (add (1 :: Int) (1 :: Int))
    "2"
    *TyFun> show (add (1 :: Integer) (1 :: Integer))
    "2"
    *TyFun> show (add (1 :: Integer) (1 :: Double))
    "2.0"
    *TyFun> show (add (1 :: Integer) (1 :: Float))
    
    <interactive>:7:1:
        No instance for (Show (SumTy Integer Float))
          arising from a use of `show'
        Possible fix:
          add an instance declaration for (Show (SumTy Integer Float))
        In the expression: show (add (1 :: Integer) (1 :: Float))
        In an equation for `it':
            it = show (add (1 :: Integer) (1 :: Float))
    
    <interactive>:7:7:
        No instance for (Add Integer Float) arising from a use of `add'
        Possible fix: add an instance declaration for (Add Integer Float)
        In the first argument of `show', namely
          `(add (1 :: Integer) (1 :: Float))'
        In the expression: show (add (1 :: Integer) (1 :: Float))
        In an equation for `it':
            it = show (add (1 :: Integer) (1 :: Float))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is the code from internalRegister method of GCMRegistrar class static void internalRegister(Context context,
The below code is from my other questions that I have asked here on
I am using this code structure below from here http://www.koonsolo.com/news/dewitters-gameloop/ to set a game
Im working with the code below from here: http://api.jquery.com/jQuery.getJSON/ $.getJSON(http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?, { format: json },
Below is selected code from one of 5 classes for this assignment. Each class
I wonder where this error is coming from. Here is the code, and below
I got the below code from an answer on a previous question here .
When I try to apply the below code from here usort($myArray, function($a, $b) {
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane.
I am creating a random ID using the below code: from random import *

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.