Hi all,
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