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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:21:42+00:00 2026-05-15T19:21:42+00:00

Here are my attempts so far: module Main where data FooT = One |

  • 0

Here are my attempts so far:

module Main where

data FooT = One | Two deriving (Show, Read)
{-
That is what I want
foo :: (Show a, Read a) => a
foo = One
-}

--class Footable (Show a, Read a) => a where
class Footable a where
  --foo2 :: (Show a, Read a) => a
  foo2 :: a

instance Footable FooT where
  foo2 = One

-- test = print foo2

I want test to compile. I don’t think the problem revolves around universal quantification. ghc says that a is a ‘strict type-variable’ edit (rigid type variable) but I don’t really comprehend what this is. The question seems to be related to this

Edit

As I wrote in my comment @sepp2k it’s probably about the existential type but I have stumbled over a curious behaviour:

This does compile:

{-# LANGUAGE OverlappingInstances, FlexibleInstances, OverlappingInstances,
UndecidableInstances, MonomorphismRestriction, PolymorphicComponents #-}
{-# OPTIONS_GHC -fno-monomorphism-restriction #-}

module Main where

    class (Num a) => Numable a where
      foo2 :: a

    instance (Num a) => Numable a where
      foo2 = 1

    instance Numable Int where
      foo2 = 2

    instance Numable Integer where
      foo2 = 3

    --test = foo2 + foo2 -- This does NOT compile (ambiguous a) 
    test = (foo2::Integer) + foo2 --this works

but this does not (`a’ is a rigid type variable message)

{-# LANGUAGE OverlappingInstances, FlexibleInstances, OverlappingInstances,
UndecidableInstances, MonomorphismRestriction, PolymorphicComponents #-}
{-# OPTIONS_GHC -fno-monomorphism-restriction #-}

module Main where

    data FooT = One | Two deriving (Show, Read)
    data BarT = Ten deriving (Show, Read)

    class (Show a, Read a) => Footable a where
      foo2 :: a

    instance (Show a, Read a) => Footable a where
      foo2 = Ten

    instance Footable FooT where
      foo2 = One

    main = print foo2

that’s so because 1 :: (Num t) => t. Can I define something (typeconstructor, consts dunno) like that?

  • 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-15T19:21:42+00:00Added an answer on May 15, 2026 at 7:21 pm

    When I uncomment the definition of test and try to compile your code, I get “ambiguous type variable”. Nothing about strictness. To understand why this is ambiguous consider this:

    module Main where
    
    data FooT = One | Two deriving (Show, Read)
    data BarT = Three | Four deriving Show
    
    class Footable a where
      foo2 :: a
    
    instance Footable FooT where
      foo2 = One
    
    instance Footable BarT where
      foo2 = Three
    
    main = print foo2  -- Should this print One or Three?
    

    Of course in your code there is only one instance of Footable, so haskell could in theory infer that you want to use the foo2 defined for FooT because that’s the only instance in scope. However if it did that, the code would break as soon as you import a module that happens to define another instance of Footable, so haskell doesn’t do that.

    To fix your problem you need to annotate foo2 with its type like so:

    module Main where
    
    data FooT = One | Two deriving (Show, Read)
    
    class Footable a where
      foo2 :: a
    
    instance Footable FooT where
      foo2 = One
    
    main = print (foo2 :: FooT)
    

    To require that all Footables be instances of Show and Read simply do:

    class (Show a, Read a) => Footable a where
      foo2 :: a
    

    Like you did in your comments, but without specifying the constraint again in the signature of foo2.

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

Sidebar

Related Questions

Here is some javascript that I wrote that attempts to change the theme of
Here are my tables in mysql: ----------------1------------------------- +---------------------------+----------+ | email | attempts | +---------------------------+----------+
Here is my attempt in jquery that kind of works but something is going
Total noob here. This is my first c# attempt, its a console application that
I guess this is a PATH/PYTHONPATH error, but my attempts failed so far to
Here's my scenario : I'm user Marius , and all I want to do
New to zepto (and honestly, far from a jQuery-whiz), I want to add a
I have an array of structures in one C# class and I want to
Im trying to write a program that limits the password to three incorrect attempts
I want a checkbox that is invisible in its unchecked state. While unchecked, hovering

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.