[Haskell-cafe] functional dependencies question
Patrick Browne
patrick.browne at dit.ie
Thu Jul 1 08:11:45 EDT 2010
Neil,
Does the following sum up the situation?
The class Num has subclasses containing various numeric types and the
literal 1 is a value for one or more of those types.
Hence the Haskell compiler says the instance 1) is OK.
But at run time, without the quantified (1:Int), the 1 could of more
than one type, which causes a problem.
Thanks for the quick and informative response,
Pat
Neil Brown wrote:
> On 01/07/10 12:37, Patrick Browne wrote:
>> Why do some cases such as 1) fail to run even if they are the only
>> instantiation.
>>
>> -- 1) Compiles but does not run
>> instance LocatedAt Int String where
>> spatialLocation(1)="home"
>>
>
> That instance is fine. I presume the problem is that you are trying to
> run this function using "spatialLocation 1" as the function call. The
> problem with that is that the "1" part has type Num a => a, i.e. it can
> be any Num type. Even though you only have one instance, that's not
> used to constrain the type for "1". The call "spatialLocation (1::Int)"
> works correctly. Looking at your other examples, all the ones that
> don't work have a numeric type for the parameter, so I suspect it is the
> same issue throughout.
>
> Thanks,
>
> Neil.
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie
More information about the Haskell-Cafe
mailing list