Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRTP regression tests #18

Open
jindraivanek opened this issue Jun 21, 2018 · 2 comments
Open

SRTP regression tests #18

jindraivanek opened this issue Jun 21, 2018 · 2 comments

Comments

@jindraivanek
Copy link

Regression tests that works in current compiler, but don't work in fix-3814 branch.

@jindraivanek
Copy link
Author

jindraivanek commented Jun 21, 2018

open System
open System.Text
open System.Runtime.CompilerServices
open System.Collections
open System.Collections.Generic
open System.Runtime.InteropServices

type Default6 = class end
type Default5 = class inherit Default6 end
type Default4 = class inherit Default5 end
type Default3 = class inherit Default4 end
type Default2 = class inherit Default3 end
type Default1 = class inherit Default2 end

type OfSeq =
    inherit Default1
    //static member inline OfSeq (x: seq<'t>                 , _: '``Foldable'<T>``               , _: Default5) = x |> Seq.map Return.Invoke |> Sum.Invoke : '``Foldable'<T>``
    static member        OfSeq (x: seq<'t>                 , _: seq<'t>                         , _: Default4) = x
    static member        OfSeq (x: seq<'t>                 , _: ICollection<'t>                 , _: Default4) = let d = ResizeArray() in Seq.iter d.Add x; d :> ICollection<'t>
    static member        OfSeq (x: seq<'t>                 , _: IList<'t>                       , _: Default4) = let d = ResizeArray() in Seq.iter d.Add x; d :> IList<'t>
    static member        OfSeq (x: seq<'t>                 , _: IList                           , _: Default4) = let d = ResizeArray() in Seq.iter d.Add x; d :> IList
    static member        OfSeq (x: seq<'k*'v>              , _: IDictionary<'k,'v>              , _: Default4) = dict x
    static member        OfSeq (x: seq<KeyValuePair<'k,'v>>, _: IDictionary<'k,'v>              , _: Default4) = x |> Seq.map (function (KeyValue x) -> x) |> dict
    static member        OfSeq (x: seq<'k*'v>              , _: IDictionary                     , _: Default4) = let d = Hashtable() in x |> Seq.iter d.Add; d :> IDictionary
    static member        OfSeq (x: seq<KeyValuePair<'k,'v>>, _: IDictionary                     , _: Default4) = let d = Hashtable() in x |> Seq.iter (function (KeyValue x) -> d.Add x); d :> IDictionary
    static member inline OfSeq (x: seq<'t>                 , _: 'R                              , _: Default3) = (^R : (new : seq<'t> -> ^R) x) : 'R
    static member inline OfSeq (x: seq<KeyValuePair<'k,'v>>, _: 'R                              , _: Default3) = (^R : (new : seq<'k*'v> -> ^R) (Seq.map (function (KeyValue x) -> x) x)) : 'R
    static member inline OfSeq (x: seq<'t>                 , _: 'F                              , _: Default2) = let c = new 'F() in (Seq.iter (fun t -> ( ^F : (member Add : 't -> ^R) c, t) |> ignore) x); c
    static member        OfSeq (x: seq<'t>                 , _: 'T when 'T :> ICollection<'t>   , _: Default1) = let d = new 'T() in x |> Seq.iter d.Add; d
    static member        OfSeq (x: seq<'k*'v>              , _: 'T when 'T :> IDictionary       , _: Default1) = let d = new 'T() in x |> Seq.iter d.Add; d
    static member        OfSeq (x: seq<KeyValuePair<'k,'v>>, _: 'T when 'T :> IDictionary       , _: Default1) = let d = new 'T() in x |> Seq.iter (function (KeyValue x) -> d.Add x); d
    static member        OfSeq (x: seq<'k*'v>              , _: 'T when 'T :> IDictionary<'k,'v>, _: OfSeq   ) = let d = new 'T() in x |> Seq.iter d.Add; d
    static member        OfSeq (x: seq<KeyValuePair<'k,'v>>, _: 'T when 'T :> IDictionary<'k,'v>, _: OfSeq   ) = let d = new 'T() in x |> Seq.iter d.Add; d
    static member inline OfSeq (x: seq<'t>                 , _: 'UserType                       , _: OfSeq   ) = ((^UserType) : (static member OfSeq: seq<'t> -> ^UserType) x)
    static member        OfSeq (x                          , _: 't []                           , _: OfSeq   ) = Array.ofSeq<'t> x
    static member        OfSeq (x                          , _: 't list                         , _: OfSeq   ) = List.ofSeq<'t> x
    static member        OfSeq (x: seq<char>               , _: string                          , _: OfSeq   ) = String.Join ("", Array.ofSeq x)
    static member        OfSeq (x: seq<char>               , _: Text.StringBuilder              , _: OfSeq   ) = (StringBuilder(), x) ||> Seq.fold (fun x -> x.Append)
    static member        OfSeq (x: seq<'t>                 , _: Stack<'t>                       , _: OfSeq   ) = Generic.Stack x

    static member inline Invoke (value: seq<'t>) = 
        let inline call_2 (a:^a, b:^b, s) = ((^a or ^b) : (static member OfSeq: _*_*_ -> _) s, b, a)
        let inline call (a:'a, s) = call_2 (a, Unchecked.defaultof<'r>, s) :'r
        call (Unchecked.defaultof<OfSeq>, value)

let inline ofSeq  (source: seq<'T> ) = OfSeq.Invoke  source : 'Collection

let x:Set<_> = ofSeq (seq{1..3})
printfn "%A" x

@jindraivanek
Copy link
Author

type Map =
    static member inline Invoke (mapping :'T->'U) (source : '``Functor<'T>``) : '``Functor<'U>`` = 
        let inline call (mthd : ^M, source : ^I, _output : ^R) = ((^M or ^I or ^R) : (static member Map: _*_*_ -> _) source, mapping, mthd)
        call (Unchecked.defaultof<Map>, source, Unchecked.defaultof<'``Functor<'U>``>)

    static member Map (x : option<_>      , f : 'T->'U, _mthd : Map) = Option.map  f x
    static member Map (x : list<_>        , f : 'T->'U, _mthd : Map) = List.map f x

let inline map f x = Map.Invoke f x

// test
map string [1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant