[Haskell-cafe] Why are these record accesses ambiguous

John Ky newhoggy at gmail.com
Sat Jun 6 03:48:19 EDT 2009


Hi Haskell Cafe,

In the following code, I get an error saying Ambiguous occurrence `x'.  Why
can't Haskell work out which x to call based on the type of getA?

Thanks

-John

#!/usr/bin/env runhaskell

> {-# LANGUAGE DisambiguateRecordFields #-}
> import A
> import B
>
> main = do
>    let xx = getA
>    putStrLn $ show x xx

----------------------

module A where

data TypeA = TypeA
   { a :: Int
   , x :: Int
   }

getA = TypeA { a = 1, x = 2 }

-------------------------

module B where

data TypeB = TypeB
   { b :: Int
   , x :: Int
   }

getB = TypeB { b = 1, x = 3 }

--------------------------

./test.lhs:8:21:
    Ambiguous occurrence `x'
    It could refer to either `A.x', imported from A at ./test.lhs:3:2-9
                                      (defined at A.hs:5:5)
                          or `B.x', imported from B at ./test.lhs:4:2-9
                                      (defined at B.hs:5:5)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090606/a16d8d47/attachment.html


More information about the Haskell-Cafe mailing list