structural-typing Questions

2

Solved

Does Typescript support a direct test for structural type compatibility? C# supports the is operator and types surface IsAssignableFrom(object instance) if (foo is SomeType) ... if (SomeType.IsA...
Spittoon asked 17/5, 2016 at 4:9

0

I am trying to do structural typing with a generic type to implement an interface as shown package main type Queue[T comparable] struct { elements []T } type QueueOperations[T comparable] ...
Dieselelectric asked 2/6, 2023 at 2:36

1

When I define Wrapper as value class(extending AnyVal): class Wrapper(val string: String) extends AnyVal def wrapperHolder(w: Wrapper): {def wrapper: Wrapper} = new { def wrapper: Wrapper = w } ...

2

Solved

I have two objects, ObjectA and ObjectB, both with a method update(). I want to write a function that accepts either ObjectA or ObjectB (but no other types). Conceptually, this is what I am trying ...
Illailladvised asked 7/3, 2012 at 23:54

4

Solved

I started looking into Go after playing around with structural typing in other languages like Scala and OCaml, and I'm trying map some of the idiomatic techniques between the languages. Consider th...
Galer asked 29/3, 2013 at 13:3

0

I want to define a typing protocol for a custom mapping class. This class needs to be very similar to a MutableMapping, except that it has a couple of additional methods beyond those those that col...
Draftee asked 18/12, 2021 at 23:32

3

Solved

Why the following is not allowed? (2.12): type Foo <: {def foo(): Unit} type Bar <: {def bar(): Unit} with Foo Looks natural to me, Bar should have both foo() and bar().
Misinform asked 12/9, 2020 at 4:47

1

Solved

I am making a logging decorator for functions in python: import logging from typing import Callable from functools import wraps def function_logging(fn: Callable) -> Callable: fn_logger = log...
Inclination asked 9/5, 2019 at 14:58

2

As mentioned in TypeScript handbook: One of TypeScript’s core principles is that type-checking focuses on the shape that values have. This is sometimes called “duck typing” or “structural subtyp...

1

Solved

A little background, I essentially need to define an int wrapper type, say MyInt (among some other classes), and another generic Interval type which can accept MyInt objects as well as other types ...
Krein asked 2/11, 2018 at 21:46

2

What is the difference between doing this export class Comment { likes: string; comment: string; constructor(likes: string, comment: string){ this.comment = comment; this.likes = likes; } }...
Subtractive asked 30/7, 2017 at 20:50

4

Solved

Assuming we have an understanding that, For explicit method definition for type X, GO compiler implicitly defines the same method for type *X and vice versa, if I declare, func (c Cat) foo(){...
Bulgar asked 29/1, 2017 at 14:49

4

Solved

In Scala, I can define structural types as follows: type Pressable = { def press(): Unit } This means that I can define a function or method which takes as an argument something that is Pressable...
Anarchism asked 14/5, 2010 at 0:42

1

This does not work as expected (since I am trying to call a package private run from outside Services): object Services { class HelloPrinter { private[Services] def run = "Hello" } } val obj ...

1

Solved

I understand I can define duck typing in generics as following trait MyTrait[A <: {def someMethod(key: String): String}] However I don't want to specify that whole big string in my trait defi...
Rosamariarosamond asked 31/3, 2015 at 12:22

6

Solved

Sometimes we have several classes that have some methods with the same signature, but that don't correspond to a declared Java interface. For example, both JTextField and JButton (among several oth...
Communicable asked 17/4, 2011 at 4:24

1

Say I have the following code: class Bar { def bar(b:Bar):Boolean = true } def func(b:Bar) = b.bar(b) The above works fine. The class Bar is defined in a 3rd party library and there are several...
Tridactyl asked 9/4, 2014 at 9:57

2

Solved

In his blog post about TypeScript, Mark Rendle is saying, that one of the things he likes about it is: "Structural typing for interfaces. I really wish C# could do that" What did he mean by th...
Makeup asked 4/10, 2012 at 5:8

1

I stumbled upon a puzzling behaviour of Type.=:= when applied on type refinments. Consider: import reflect.runtime.universe._ type T1 = AnyRef { def apply( name: String ): Unit def foo: String }...
Blabber asked 7/2, 2014 at 13:59

4

Solved

I have heard Haskell described as having structural typing. Records are an exception to that though as I understand. For example foo cannot be called with something of type HRec2 even though HRec a...
Quadratic asked 12/1, 2014 at 5:22

1

Solved

Suppose we want to write a macro that defines an anonymous class with some type members or methods, and then creates an instance of that class that's statically typed as a structural type with thos...
Nonresistant asked 17/1, 2013 at 1:31

3

Solved

What are the differences between typeclasses and Abstract Data Types? I realize this is a basic thing for Haskell programmers, but I come from a Scala background, and would be interested in exampl...

3

Solved

I have two case classes case class StringCaseClass(argument: String) case class IntCaseClass(argument: Int) I want to define a structural type which will match the companion object of both of t...
Crushing asked 24/3, 2013 at 13:2

1

Solved

While researching about structural typing I found the following post describing how interfaces in Go are translated to method lookup tables at runtime. The process described in the post seems vastl...
Sturm asked 7/3, 2013 at 22:48

1

Solved

Can we get the type of val s: String using reflection from the outside of the function f? val f = (r: {val s: String}) => { }
Watchband asked 1/11, 2012 at 21:1

© 2022 - 2024 — McMap. All rights reserved.