interop — examples
← all topics · 63 examples · page 1 of 2 · raw source ↓
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ErrorPropagationTests.cs::ForKV_MaxByValue topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Collections.Generic"
func go() -> string {
let d = Dictionary<string, int>()
d["a"] = 3
d["b"] = 9
d["c"] = 5
var best = ""
var bestN = 0
for (k, v) in d {
if v > bestN {
bestN = v
best = k
}
}
return best
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ErrorPropagationTests.cs::ForKV_SumsValues topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Collections.Generic"
func go() -> int {
let d = Dictionary<string, int>()
d["a"] = 10
d["b"] = 20
d["c"] = 30
var sum = 0
for (k, v) in d {
sum += v
}
return sum
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ErrorPropagationTests.cs::ForKV_UsesKey topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Collections.Generic"
func go() -> int {
let d = Dictionary<string, int>()
d["xy"] = 1
d["z"] = 1
var totalKeyLen = 0
for (k, v) in d {
totalKeyLen += k.Length
}
return totalKeyLen
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::GenericConstructorCall_InFunction_IL topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func make() -> string {
let d = Dictionary<string, int>()
return "ok"
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::GenericConstructorCall_InInit_ParsesAndBinds topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
ref data Store {
items: List<int>
lookup: Dictionary<string, int>
init() {
self.items = List<int>()
self.lookup = Dictionary<string, int>()
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::GenericConstructorCall_Nested_ParsesCorrectly topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func make() -> int {
let m = Dictionary<string, List<int>>()
return 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::GenericConstructorCall_Parser_ParsesCorrectly topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func make() -> int {
let d = Dictionary<string, int>()
return 0
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::GenericExternalType_Dictionary_ResolvesCorrectly topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data Lookup {
entries: Dictionary<string, int>
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::GenericExternalType_Nested_ResolvesCorrectly topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data Nested {
mapping: Dictionary<string, List<int>>
}Runs `run` → 185
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::Indexer_DictionaryGetSet_StringIntRoundTrip topic: interop status: verified
// verified behavior: Test.run(...) == 185
namespace Test
func run() -> int {
let scores = Dictionary<string, int>()
scores["alice"] = 100
scores["bob"] = 85
return scores["alice"] + scores["bob"]
}Runs `run` → 100
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::Out_DictionaryTryGetValue topic: interop status: verified
// verified behavior: Test.run(...) == 100
namespace Test
func run() -> int {
let scores = Dictionary<string, int>()
scores["alice"] = 100
if scores.TryGetValue("alice", out var score) {
return score
}
return -1
}Runs `run` → 128
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::Property_SetOnBclObject_StringBuilderCapacity topic: interop status: verified
// verified behavior: Test.run(...) == 128
namespace Test
func run() -> int {
let sb = StringBuilder()
sb.Capacity = 128
return sb.Capacity
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Generics_DictionaryStringToValueData topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data Score { points: int }
func go() -> int {
let m = Dictionary<string, Score>()
m["a"] = Score { points: 5 }
m["b"] = Score { points: 9 }
return m["a"].points + m["b"].points
}ILEmitterTests_Coverage_Adversarial__Reflection_CountDeclaredMethodsViaInstanceType
interop unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Reflection_CountDeclaredMethodsViaInstanceType topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Reflection"
data Widget { id: int }
func go() -> bool {
let w = Widget { id: 1 }
let methods = w.GetType().GetMethods()
return methods.Length >= 1
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Added_DictStringToInt topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var m = Dictionary<string, int>()
m["a"] = 3
return m["a"]
}Runs `go` → "0123"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Algo_StringBuilderAccumulate topic: interop status: verified
// verified behavior: Test.go(...) == "0123"
namespace Test
func go() -> string {
let sb = StringBuilder()
for i in 0..4 {
sb.Append(i.ToString())
}
return sb.ToString()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Dict_ContainsKey topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> bool {
let d = Dictionary<string, int>()
d["k"] = 1
return d.ContainsKey("k")
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Dict_Count topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let d = Dictionary<string, int>()
d["a"] = 1
d["b"] = 2
return d.Count
}Runs `go` → "hello"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Dict_IntKey topic: interop status: verified
// verified behavior: Test.go(...) == "hello"
namespace Test
func go() -> string {
let d = Dictionary<int, string>()
d[1] = "hello"
return d[1]
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Dict_OverwriteValue topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let d = Dictionary<string, int>()
d["k"] = 1
d["k"] = 2
return d["k"]
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Dict_TryGetValue topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let d = Dictionary<string, int>()
d["k"] = 7
if d.TryGetValue("k", out var v) {
return v
}
return -1
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::Nested_DictOfList topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let d = Dictionary<string, List<int>>()
d["nums"] = [10, 20]
return d["nums"].Count
}ILEmitterTests_Coverage_Collections__RP_Dict_ComparerCtor_IsCaseInsensitive
interop unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_Dict_ComparerCtor_IsCaseInsensitive topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var d = Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
d["A"] = "1"
d["a"] = "2"
return d.Count
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_NilDict_ReassignThenSet topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var d: Dictionary<string, string> = nil
if d == nil { d = Dictionary<string, string>() }
d["k"] = "v"
return d.Count
}ILEmitterTests_Coverage_Collections__RP_ReadOnlyDict_CovariantAssign_AndCount
interop unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Collections.cs::RP_ReadOnlyDict_CovariantAssign_AndCount topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
var d = Dictionary<string, string>()
d["a"] = "x"
d["b"] = "y"
let ro: IReadOnlyDictionary<string, string> = d
return ro.Count
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Data.cs::Dictionary_PutGet topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let d = Dictionary<string, int>()
d["answer"] = 42
return d["answer"]
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Misc.cs::Bcl_StringBuilder topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
func go() -> int {
let sb = StringBuilder()
sb.Append("foo")
sb.Append("bar")
return sb.ToString().Length
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_Parse topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Globalization"
func go() -> double { return double.Parse("3.14", CultureInfo.InvariantCulture) }ILEmitterTests_ExternalReflection__AmbiguousExternalType_AcrossImports_ReportsES2151
interop negative verifiedRejected at compile time: ES2151
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::AmbiguousExternalType_AcrossImports_ReportsES2151 topic: interop status: verified
// verified behavior: reports diagnostic ES2151
namespace Test
using "System.Threading"
using "System.Timers"
func go() -> int {
let t = Timer()
return 0
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::IReadOnlyListInt_Count_AsInt topic: interop status: verified
// verified behavior: Test.go(...) == 2
namespace Test
func makeList() -> IReadOnlyList<int> {
let xs = List<int>()
xs.Add(1)
xs.Add(2)
return xs
}
func go() -> int {
let ro = makeList()
return ro.Count
}Runs `go` → "n=1"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::IReadOnlyListInt_Count_Interpolated topic: interop status: verified
// verified behavior: Test.go(...) == "n=1"
namespace Test
func makeList() -> IReadOnlyList<int> {
let xs = List<int>()
xs.Add(7)
return xs
}
func go() -> string {
let ro = makeList()
return "n={ro.Count}"
}Runs `go` → "2"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::IReadOnlyListInt_Count_PassedAsCallArg topic: interop status: verified
// verified behavior: Test.go(...) == "2"
namespace Test
using "System.Text"
func makeList() -> IReadOnlyList<int> {
let xs = List<int>()
xs.Add(2)
xs.Add(5)
return xs
}
func go() -> string {
let ro = makeList()
let sb = StringBuilder()
sb.Append(ro.Count)
return sb.ToString()
}Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::ListInt_Count_AsInt topic: interop status: verified
// verified behavior: Test.go(...) == 3
namespace Test
func go() -> int {
let xs = List<int>()
xs.Add(1)
xs.Add(2)
xs.Add(3)
return xs.Count
}Runs `go` → "count=2"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::ListInt_Count_Interpolated topic: interop status: verified
// verified behavior: Test.go(...) == "count=2"
namespace Test
func go() -> string {
let xs = List<int>()
xs.Add(1)
xs.Add(2)
return "count={xs.Count}"
}Runs `go` → 1
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::ListObject_BoxInt_ReadBackElement topic: interop status: verified
// verified behavior: Test.go(...) == 1
namespace Test
func go() -> int {
let xs = List<object>()
xs.Add(42)
let arr = xs.ToArray()
return arr.Length
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::ListObject_BoxInt_ToArray_Length topic: interop status: verified
// verified behavior: Test.go(...) == 2
namespace Test
func go() -> int {
let xs = List<object>()
xs.Add(10)
xs.Add(20)
let arr = xs.ToArray()
return arr.Length
}Runs `go` → ".txt"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::MultiSegmentQualifiedStaticCall_Works topic: interop status: verified
// verified behavior: Test.go(...) == ".txt"
namespace Test
func go() -> string {
return System.IO.Path.GetExtension("file.txt")
}ILEmitterTests_ExternalReflection__OfType_ExplicitGenericArg_FiltersHeterogeneousList
interop runnable verifiedRuns `go` → 4
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::OfType_ExplicitGenericArg_FiltersHeterogeneousList topic: interop status: verified
// verified behavior: Test.go(...) == 4
namespace Test
func go() -> int {
let xs = List<object>()
xs.Add(1)
xs.Add("two")
xs.Add(3)
xs.Add("four")
var sum = 0
for n in xs.OfType<int>() {
sum += n
}
return sum
}ILEmitterTests_ExternalReflection__OfType_ResultElementType_AllowsMemberAccess
interop runnable verifiedRuns `go` → 5
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::OfType_ResultElementType_AllowsMemberAccess topic: interop status: verified
// verified behavior: Test.go(...) == 5
namespace Test
func go() -> int {
let xs = List<object>()
xs.Add("ab")
xs.Add(7)
xs.Add("cde")
var total = 0
for s in xs.OfType<string>() {
total += s.Length
}
return total
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::QualifiedConstruction_External_Works topic: interop status: verified
// verified behavior: Test.go(...) == 2
namespace Test
func go() -> int {
let sb = System.Text.StringBuilder()
sb.Append(42)
return sb.Length
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::TypeAlias_Construction_Works topic: interop status: verified
// verified behavior: Test.go(...) == 2
namespace Test
using SB = "System.Text.StringBuilder"
func go() -> int {
let sb = SB()
sb.Append(42)
return sb.Length
}Runs `go` → 5
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::TypeAlias_ParameterPosition_Works topic: interop status: verified
// verified behavior: Test.go(...) == 5
namespace Test
using SB = "System.Text.StringBuilder"
func length(b: SB) -> int = b.Length
func go() -> int {
let sb = SB()
sb.Append("hello")
return length(sb)
}Runs `go` → 3.0
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::TypeAlias_ResolvesCollision topic: interop status: verified
// verified behavior: Test.go(...) == 3.0
namespace Test
using "System.Threading"
using TTimer = "System.Timers.Timer"
func go() -> double {
let t = TTimer()
t.Interval = 3.0
return t.Interval
}Runs `go` → ".txt"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_ExternalReflection.cs::UsingStaticMultiSegment_BareCall_Works topic: interop status: verified
// verified behavior: Test.go(...) == ".txt"
namespace Test
using static "System.IO.Path"
func go() -> string {
return GetExtension("file.txt")
}ILEmitterTests_Integration__PerFileImportScoping_BareExternalNameResolvesToOwnFileImport
interop unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::PerFileImportScoping_BareExternalNameResolvesToOwnFileImport topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Timers"
func ta(x: Timer) -> int = 1Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::Reflection_AssemblyContainsTypes topic: interop status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
using "System.Reflection"
data Marker { v: int }
func go() -> bool {
let t = Marker { v: 1 }
let asm = t.GetType().Assembly
return asm.GetTypes().Length > 0
}Runs `run` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interop.cs::ArrowLambda_InfersParameterType topic: interop status: verified
// verified behavior: Test.run(...) == 7
namespace Test
func apply(x: int, f: Func<int, int>) -> int {
return f(x)
}
func run() -> int {
return apply(5, (x) => x + 2)
}Runs `run` → "ok"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interop.cs::ArrowLambda_TypedParameter topic: interop status: verified
// verified behavior: Test.run(...) == "ok"
namespace Test
func applyText(f: Func<string, string>) -> string {
return f("ok")
}
func run() -> string {
return applyText((value: string) => value)
}Runs `run` → 19
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interop.cs::ArrowLambda_ZeroArgMultiArgCaptures topic: interop status: verified
// verified behavior: Test.run(...) == 19
namespace Test
func compute(f: Func<int>) -> int {
return f()
}
func combine(f: Func<int, int, int>) -> int {
return f(3, 4)
}
func run() -> int {
let offset = 5
let left = compute(() => 7)
let right = combine((x, y) => x + y + offset)
return left + right
}Runs `run` → 60
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interop.cs::ForIn_ListOfInt_SumsElements topic: interop status: verified
// verified behavior: Test.run(...) == 60
namespace Test
func run() -> int {
let xs = [10, 20, 30]
var total = 0
for x in xs { total += x }
return total
}