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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:32:55+00:00 2026-05-15T13:32:55+00:00

I have an ambiguous type variable error on the definition of trial below, I

  • 0

I have an ambiguous type variable error on the definition of “trial” below, I am wondering if there is anything that can be done to make this situation work? I want to really just deal with instances and not explicit data types (such as the MO1, MO2 included below).

module Tc102 where

class (Show a, Read a) => MyObj a where
    alpha :: a->String
    beta  :: a->Int

data MO1 = MO1 { a1 :: String, b1 :: Int } deriving (Show,Read)
data MO2 = MO2 { a2 :: String, b2 :: Int } deriving (Show,Read)

instance MyObj MO1 where
    alpha = a1
    beta = b1

instance MyObj MO2 where
    alpha = a2
    beta = b2


a = MO1 "a" 3
b = MO2 "b" 4

test :: MyObj a => a->String
test = alpha


showMe :: (MyObj a)=> a -> String
showMe = show

readMe :: (MyObj a) => String -> a
readMe = read

trial :: MyObj a => a -> String
trial = test . readMe . showMe

thanks in advance all! I fear however i might need to go to a helper function that would convert old ADT to the ‘latest versions…

Simon

EDIT To clarify, imagine that I first show to a file, then later reload the object. Then the function i have is more like

trial :: String -> Int
trial s = beta x
  where x = readMe s
  • 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-15T13:32:55+00:00Added an answer on May 15, 2026 at 1:32 pm

    You can’t read compile-time type from run-time file. You should explicitly implement run-time type-varying value.

    As example:

    data AnyMyObj = forall a . MyObj a => AnyMyObj a
    
    test :: AnyMyObj -> String
    test (AnyMyObj x) = alpha x
    
    showMe :: AnyMyObj -> String
    showMe (AnyMyObj x) = show x
    
    readMe :: String -> AnyMyObj
    readMe s = AnyMyObj (read s :: MO1) -- maybe something more complicated
    
    trial :: AnyMyObj -> String
    trial = test . readMe . showMe
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is a small test case that demonstrates a problem that I am trying
I have a UserControl that is part of a Class library. I reference this
I have the following haskell code: fac n = product [1..n] taylor3s w0 f
The purpose for this particular portion of code is to make the size function
I have a class with an overloaded method: MyClass.DoThis(Action<Foo> action); MyClass.DoThis(Action<Bar> action); I want
I am trying to improve SQLite error handling in an existing C++ program. I
In a code-behind for an .aspx in one of my test web projects, I'm
I'd like to write two distinct functions to handle a constant value and a
In working on Kira3, I was playing around with the C++ compiler and looking

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.