adhoc-polymorphism

How to express mixed ad-hoc and parametric polymorphic in typescript?

我的未来我决定 提交于 2019-12-13 03:20:10
问题 I'm not sure if I'm describing the questing currently in the title. What I'm trying to ask comes from the following requirement. I'm trying to make an abstract for states of finite state machines and comes up with the following definition (in typescript) interface IState { send<T, E>(message: T, callback?:(event: E)=>void): IState; } I'm trying to express that a state of the finite state machine should be able to accept messages and return new state, with an optional callback to handle event

F#: arithmetic operator and loss of polymorphism (value restriction?)

与世无争的帅哥 提交于 2019-12-11 20:42:23
问题 This code doesn't compile: let f = fun x y -> x <<< y // bit shift let g = fun x y -> x <<< y [<EntryPoint>] let main _ = printfn "%d" <| f 1 10 printfn "%d" <| f 1L 10 // error printfn "%d" <| g 1L 10 0 (7,21): error FS0001: This expression was expected to have type int but here has type int64 http://ideone.com/qktsOb I guess the unifier fixed the type parameters associated with f and g upon seeing their first occurrences. What governs this process? I think this is very similar to "value

Polymorphism in OCaml - ad hoc,parametric, inclusion/subtyping

孤人 提交于 2019-12-09 13:19:20
问题 I am having a problem understanding the different types of polymorphism, specifically in regards to OCaml. I understand that polymorphism allows for multiple types in OCaml denoted as 'a, but I do not understand what the different types of polymorphism are. If someone could give me an explanation with relatively low-level language that would be awesome! ad hoc, parametric, inclusion/subtyping 回答1: Here's an approximation. Ad-hoc polymorphism usually refers to being able to declare the same

Type inference interferes with referential transparency

这一生的挚爱 提交于 2019-12-04 16:00:00
问题 What is the precise promise/guarantee the Haskell language provides with respect to referential transparency? At least the Haskell report does not mention this notion. Consider the expression (7^7^7`mod`5`mod`2) And I want to know whether or not this expression is 1. For my safety, I will do perform this twice: ( (7^7^7`mod`5`mod`2)==1, [False,True]!!(7^7^7`mod`5`mod`2) ) which now gives (True,False) with GHCi 7.4.1. Evidently, this expression is now referentially opaque. How can I tell

Polymorphism in OCaml - ad hoc,parametric, inclusion/subtyping

瘦欲@ 提交于 2019-12-03 16:21:53
I am having a problem understanding the different types of polymorphism, specifically in regards to OCaml. I understand that polymorphism allows for multiple types in OCaml denoted as 'a, but I do not understand what the different types of polymorphism are. If someone could give me an explanation with relatively low-level language that would be awesome! ad hoc, parametric, inclusion/subtyping Here's an approximation. Ad-hoc polymorphism usually refers to being able to declare the same name (usually a function) with different types, e.g. + : int -> int -> int and + : float -> float -> float in