type-equivalence

Implementing type equation generator in OCaml

Deadly 提交于 2019-12-08 08:24:36
问题 type exp = | CONST of int | VAR of var | ADD of exp * exp | SUB of exp * exp | ISZERO of exp | IF of exp * exp * exp | LET of var * exp * exp | PROC of var * exp | CALL of exp * exp and var = string type typ = TyInt | TyBool | TyFun of typ * typ | TyVar of tyvar and tyvar = string type typ_eqn = (typ * typ) list module TEnv = struct type t = var -> typ let empty = fun _ -> raise (Failure "Type Env is empty") let extend (x,t) tenv = fun y -> if x = y then t else (tenv y) let find tenv x = tenv

Implementing type equation generator in OCaml

为君一笑 提交于 2019-12-06 16:28:27
type exp = | CONST of int | VAR of var | ADD of exp * exp | SUB of exp * exp | ISZERO of exp | IF of exp * exp * exp | LET of var * exp * exp | PROC of var * exp | CALL of exp * exp and var = string type typ = TyInt | TyBool | TyFun of typ * typ | TyVar of tyvar and tyvar = string type typ_eqn = (typ * typ) list module TEnv = struct type t = var -> typ let empty = fun _ -> raise (Failure "Type Env is empty") let extend (x,t) tenv = fun y -> if x = y then t else (tenv y) let find tenv x = tenv x end let rec gen_equations : TEnv.t -> exp -> typ -> typ_eqn =fun tenv e ty -> match e with | CONST n

Should I Overload == Operator?

ⅰ亾dé卋堺 提交于 2019-12-04 13:56:05
How does the == operator really function in C#? If it used to compare objects of class A , will it try to match all of A 's properties, or will it look for pointers to the same memory location (or maybe something else)? Let's create a hypothetical example. I'm writing an application that utilizes the Twitter API, and it has a Tweet class, which has all the properties of a single tweet: text, sender, date&time, source, etc. If I want to compare objects of class Tweet for equivalence, can I just use: Tweet a, b; if (a == b) { //do something... } Will that check for equivalence of all the

structural equivalence vs name equivalence

别说谁变了你拦得住时间么 提交于 2019-12-04 10:15:22
问题 I can't seem to grasp exactly what name equivalence is. I'm pretty sure I have structural down though. An example my professor gave was this: Type TI=integer Type TTI=TI a=integer b=TTI f= ref float g= ref float a and b are both structural and name equivalent, while f and g are just structural equivalent.I don't understand why a and b would be name equivalent, but f and g aren't. 回答1: Type Equality The meaning of basic operations such as assignment (denoted by = in C) is specified in a

structural equivalence vs name equivalence

巧了我就是萌 提交于 2019-12-03 06:10:18
I can't seem to grasp exactly what name equivalence is. I'm pretty sure I have structural down though. An example my professor gave was this: Type TI=integer Type TTI=TI a=integer b=TTI f= ref float g= ref float a and b are both structural and name equivalent, while f and g are just structural equivalent.I don't understand why a and b would be name equivalent, but f and g aren't. Type Equality The meaning of basic operations such as assignment (denoted by = in C) is specified in a language definition. Thus, for example, the meaning of statements such as x = y; here the value of object y is

'idiomatic' Haskell type inequality

帅比萌擦擦* 提交于 2019-12-01 09:20:42
(edited from previous question where I thought code below doesn't work) I wish to implement a haskell function f that has a restriction such that its 2 parameters must not have the same type. I have used the following code: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances, FlexibleInstances, FlexibleContexts, TypeFamilies, IncoherentInstances #-} data HTrue = HTrue data HFalse = HFalse class HEq x y b | x y -> b instance (b ~ HTrue) => HEq x x b instance (b ~ HFalse) => HEq x y b g :: (HEq a b HFalse) => a -> b -> () g x y = () Now the function g only accepts a

'idiomatic' Haskell type inequality

懵懂的女人 提交于 2019-12-01 07:38:11
问题 (edited from previous question where I thought code below doesn't work) I wish to implement a haskell function f that has a restriction such that its 2 parameters must not have the same type. I have used the following code: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances, FlexibleInstances, FlexibleContexts, TypeFamilies, IncoherentInstances #-} data HTrue = HTrue data HFalse = HFalse class HEq x y b | x y -> b instance (b ~ HTrue) => HEq x x b instance (b ~

Why does getpid() return pid_t instead of int?

a 夏天 提交于 2019-11-29 23:11:54
What's the logic behind calls like getpid() returning a value of type pid_t instead of an unsigned int ? Or int ? How does this help? I'm guessing this has to do with portability? Guaranteeing that pid_t is the same size across different platforms that may have different sizes of int s etc.? I think it's the opposite: making the program portable across platforms, regardless of whether, e.g., a PID is 16 or 32 bits (or even longer). The reason is to allow nasty historical implementations to still be conformant. Suppose your historical implementation had (rather common): short getpid(void); Of

Why does getpid() return pid_t instead of int?

こ雲淡風輕ζ 提交于 2019-11-28 19:32:08
问题 What's the logic behind calls like getpid() returning a value of type pid_t instead of an unsigned int ? Or int ? How does this help? I'm guessing this has to do with portability? Guaranteeing that pid_t is the same size across different platforms that may have different sizes of int s etc.? 回答1: I think it's the opposite: making the program portable across platforms, regardless of whether, e.g., a PID is 16 or 32 bits (or even longer). 回答2: The reason is to allow nasty historical

C#: Oracle Data Type Equivalence with OracleDbType

一世执手 提交于 2019-11-27 01:03:10
Situation: I am creating an app in C# that uses Oracle.DataAccess.Client (11g) to do certain operations on a Oracle database with stored procedures. I am aware that there is a certain enum (OracleDbType) that contains the Oracle data types, but I am not sure which one to use for certain types. Questions: What is the equivalent Oracle PL/SQL data type for each enumerated type in the OracleDbType enumeration ? There are three types of integer (Int16, Int32, Int64) in the OracleDbType... how to know which one to use or are they all suppose to work? The values of the OracleDbType Enumeration are