Hide this comment

Thanks, I logged a bug.

By on 4/23/2010 10:23 AM ()Reply
Hide this comment

Probably related to the previous one.

> type I1 =
abstract f : int -> int
;;

type I1 =
interface
abstract member f : int -> int
end

> type I2 =
abstract makeI1 : int -> #I1
;;

type I2 =
interface
abstract member makeI1 : int -> #I1
end

> type C1() =
interface I1 with
member this.f x = x
interface I2 with
member this.makeI1 x = this
;;

member this.makeI1 x = this
-------------------------------^^^^

stdin(13,32): error FS0001: This expression was expected to have type
'a
but here has type
C1

By on 4/28/2010 4:12 PM ()Reply
Hide this comment

I don't think that this is a bug; it looks like the type of your makeI1 member is incorrect based on the '#' prefix on I1 - as you have written it, given a value i2 of type I2, and given any type t derived from I1 and any int n, i2.makeI1(n) must return a value of type t. This works, though:

1
2
3
4
5
6
7
8
9
10
11
type I1 =
    abstract f : int -> int

type I2 =
    abstract makeI1 : int -> I1

type C() =
  interface I1 with
    member x.f(i)  = i
  interface I2 with
    member x.makeI1(i) = (x :> I1)
By on 4/28/2010 7:51 PM ()Reply
Hide this comment

Ok, according to the spec this one is not a bug.

During checking, type is first checked and converted to a static type, then constraints are checked and added to the current inference constraints.

Here compiler fails to find the most general type without the constraints, and honestly reports the problem.

It would be nice to get a bit more meaningful error message (relating to the #I1, not to 'a as a part of 'a when 'a :> I1), but I can live without that [;)].

Does it, in practice, mean that one can only use flexible types for function/constructor/... arguments, but not in (return) values?

Back to the up-casts in the object-oriented code... I'm almost fine with the idioms like:

1
2
3
4
5
6
7
type C() =
  member this.i1 = this :> I1
  interface I1 with
    member this.f(i)  = i
  member this.i2 = this :> I2
  interface I2 with
    member this.makeI1(i) = this.i2

Probably there's some idiom I'm lacking due to insignificant experience with the ML-based languages?

By on 4/29/2010 3:12 AM ()Reply
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper

Logging in...