Replies: 4 comments
-
Sounds like you want shapes from #164. public shape SReadOnlyList<T>
{
//your shape definition
}
public shape SReadOnlyDictionary<TKey, TValue>
{
//your shape definition
}
public shape SList<T>
{
//your shape definition
}
public void MyComplexOperation<T1, T2, T3>(
IReadOnlyDictionary<string, T1> arg1, IReadOnlyDictionary<string, T2> arg2)
where T1: SReadOnlyList<T1>
where T2: SReadOnlyDictionary<string, T3>
where T3: SList<string>
{
// Do something complex.
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Actually it's additional feature that it's well works with shapes suggested by you. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This feature exists in F# as "flexible types", with void M<T>(IReadOnlyDictionary<string, #IReadOnlyList<T>> arg)
// equivalent to
void M<T, TList>(IReadOnlyDictionary<string, TList> arg) where TList : IReadOnlyList<T> |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you for pointing. I renamed this issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Suppose you have some method:
Unfortunately IReadOnlyDictionary is not contravariant and Dictionary<string, List <int>> or Dictionar<string, int[]> is not supported directly by the method.
We can workaround this:
Looks ugly but works well.
Imagine that method will have 5+ parameters and most of parameters will have Dictionary - like contravariance problem. The same approach is possible but will completely kill code readability.
We can introduce "Ultra generic" syntax like this
which is translates to classic c# 2.0 generic method:
So it is just syntax sugar, no any changes to CLR are required.
Beta Was this translation helpful? Give feedback.
All reactions