[Haskell-beginners] accessor function scope

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Tue Apr 7 13:31:40 EDT 2009


On 2009 Apr 7, at 9:00, John Dorsey wrote:
>> I've noticed that if I declare two types like this
>>
>> data Thing1 = Thing1 { itemPos :: Int }
>> data Thing2 = Thing2 { itemPos :: Int }
>>
>> then I get the error "Multiple declarations of Main.itemPos"
>
> Here's something to consider.  What's the type of itemPos?  In the  
> above
> code, it can't be
>
>  itemPos :: Thing1 -> Int
>
> because you want to be able to apply it to a Thing2.  I suppose the
> compiler could, behind the scenes, create a typeclass like this:

I think it already does this if you ask for the  
DisambiguateRecordFields language extension (provided it can tell  
which one is needed!).

>> For that matter, I don't know what the term is for a "StaffItem-type
>> LayoutItem". The type is clearly LayoutItem. "StaffItem" is the
>> constructor. How do you refer to the concept of a LayoutItem  
>> constructed
>> via a StaffItem?
>
> You can just call it "a StaffItem", I guess.  I don't know if  
> there's a
> common term.  But you're right that it's type is LayoutItem.

Technically LayoutItem is a sum of products and StaffItem is a variant  
(see http://en.wikipedia.org/wiki/Sum_type for more information).

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20090407/163e8167/PGP.bin


More information about the Beginners mailing list