[Haskell] Annoying naming clashes

Tom Pledger tpledger at ihug.co.nz
Wed Jun 16 05:43:59 EDT 2004


Ben.Yu at combined.com wrote:

>Tom,
>Then what will you do when naming operations in a class? Is it right that
>care has to be taken in order not to conflict with other classes?
>
>Say, I have a Person class where I want to define an operation "getName".
>Is it wise to name it "getPersonName" instead?
>

Class method names support the small-modules-and-qualified-names 
approach too.

    module C1 where
    class C1 a where
        c :: Int -> a

    module C2 where
    class C2 a where
        c :: Int -> a

    module UseBoth where
    import C1
    import C2
    f i = (C1.c i, C2.c i)


This can cause trouble if you use C1 extensively without C2, and *then* 
import C2: you'd have to change a lot of unqualified c to C1.c. But when 
you're using C1 in the first place, you can guess whether you should 
write C1.c in anticipation of clashes.

>I notice that FiniteMap always names operations and functions xxxFM,
>although that looks ugly to me. Is that a general good thing to do when
>naming operations?
>

It's not my preferred approach, but opinions vary.

Regards,
Tom




More information about the Haskell mailing list