Types SWIG / Lua: Determine member field data type

SWIG graciously provides the swig_type() function to get a string representation of the data type of a passed userdata object. However, in the case of member fields, SWIG and Lua consider those to be simple "number" items and so prints only "number" instead of the data type's name. e.g. typedef num_years int; class Person { public: Person * spouse; num_years age; }; in C++ would result in: Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > p = MyModule.P

Single vs Double datatypes

Are there any situations where it would make more sense to use a single datatype instead of a double? From my searching, the disadvantage to a double is that it requires more space, which isn't a problem for most applications. In that case, should all floating point numbers be doubles? A little background info: I'm working with an application that deals with a lot of data about coordinates and chemicals. A few customers have noticed that when importing spreadsheets of data, some values with h

Types Search for *.html in a folder and run specific code

type "S:\Images*.html" | findstr /v Signature | findstr /v sealants | findstr /v construction >S:\Images\.html I have developed the above text. I am not the best at batch scripting however know my way around how to use variables (in PHP and C++). My goal is to update users email signature file. (I am trying to remove three lines of text). In order to do this I want to search their shared drive for any html files and try and find the three lines I need to remove. The catch is I am not very g

Types Ensure a type implements an interface at compile time in Go

How can I ensure that a type implements an interface at compile time? The typical way to do this is by failure to assign to support interfaces from that type, however I have several types that are only converted dynamically. At runtime this generates very gruff error messages, without the better diagnostics given for compile time errors. It's also very inconvenient to find at run time that types I expected to support interfaces, do in fact not.

Types Accessing members of ocaml record when differant record type have common label

I have define two record types as follow: (* in module A*) type reg = {name: string; mutable value: Big_int.big_int} type exp = Reg of reg | Other (* in module B*) type abstr = Top | Bot | Elt of int type register = {name: string; mutable value: abstr} In module B, I have a list, that I call l, of exp and I'm doing a patter matching on it. So I have something like this: List.fold_left (fun l elt -> let str = match elt with | A.Reg r -> r.name | _

Types OCaml unexpected type mismatch in tuples

I'm trying to write a function, that takes an integer and a triplet and returns an element of the triplet at the given position (exercise 5.3 from Hickey's book). Triplet should be able to contain elements of different types. I thought, that if I write 3 little functions, each returning a specific element of the triple and make my big function return one of them accordingly, then it would do the trick, but it doesn't work. I've tried to fiddle with this "eta-expansion" concept, but I didn't ge

Types Type inference in the source of OCaml

I would like to take a close look at the implementation of type inference in OCaml, my OCaml seems be installed in /usr/local/lib/ocaml, but no .ml inside seems include the piece of code for type inference... Could anyone help?

Types How to declare child's type in parent class?

Dart code: main() { var child1 = new Child1(); var t = child1.childType(); } class Parent { ??? childType() { return this.runtimeType; } } class Child1 extends Parent { } class Child2 extends Parent { } You can see the ??? in class Parent, I want it to reference to child's type, but I don' know how to declare it. In scala, it can be: def childType(): this.type = { ... } But I don't know how to do it in dart. Is it possible? If not possible, what's the best t

Types OCaml: type incompatibilities between sets

I'm having troubles with type incompatibilities in OCaml. First, I have a file setBuilder.ml where I define a functor SO that creates an order for sets, a functor S that creates sets, and a functor SM that creates a module containing useful functions to work with sets: module SO (M: sig type t end) = struct type t = M.t let compare = Pervasives.compare end module S (P: sig type t end): Set.S with type elt = P.t = Set.Make (SO (P)) module SM (M: sig type t end): sig type t =

Types How to retrieve Lotus Notes attachments?

I’m trying to export all of the documents and their attachments from a Lotus Notes database (with Designer 7.0). I can get the document data and can get an attachment, but only if I hard code the name. The two methods, in LotusScript, I’ve found for getting the filename programmatically aren’t working, as shown in the lower two code blocks. In the first, doc.GetFirstItem( "Body" ) returns Nothing, and in the second, there’s a Type Mismatch during execution on the Forall line. Any help on how

Types CUDA mixing float and double causing kernel to not execute

Using CUDA C I have a statistics kernel that when I add a breakpoint in VS2012 anywhere within the kernel and include the stddev line with the preceding variable definitions: double mean, stddev, sumOfValues, sumOfValuesSquared; unsigned int n; // acquire greater than 0 values for: sumOfValues, sumOfValuesSquared, and n stddev = (float)(sqrt((double)(n) * sumOfValuesSquared - (sumOfValues*sumOfValues)) / (double)(n)); The breakpoint is never reached, and the kernel does not execute. When I

Types F# function type mismatch

What's wrong with my test function? let divisorOf(d, n) = n % d = 0 let notDivisible(d, n) = not (divisorOf(d, n)) let rec test(a, b, c) = function | (a, b, _) when (a > b) -> true | (a, b, c) -> notDivisible(a, c) && test(a + 1, b, c) I'm getting a compiler error that the expression on line 7 has function type, not bool. (7,40): error FS0001: This expression was expected to have type bool but here has type 'a * 'a * 'b -> bool

Consuming Discriminated Union types in variable bindings

I have made a custom type and would like to create 2 variables that prove my type works as expected. type number = A of int | B of float;; let a = 0;; let b = 0.0;; How should I change the variable declarations to force them to type number? Currently a is int and b is float.

Types Fibonacci program in Scheme (using define-datatype)

I have been trying to write the Fibonacci program in scheme using the define-datatype approach but am unable to do so. Please tell me how its done. I have written the representation independence code below: (define (top-k k) k) (define (applyk k n) (k n)) (define (fibind n k) (cond [(= n 0) (k 1)] [(= n 1) (k 1)] [else (fibind (- n 1) (fib1 n k))])) (define fib1 (lambda (n k) (lambda (v) (fibind (- n 2) (lambda (w) (k (+ v w))))))) EDIT: I basically want a code

Types OCaml : How to get a parameter from a type?

This is really simple but I can't find the answer to it anywhere. Let's say I created a new type student = string * int which is a tuple of a student's name and his score on a test. Then a list of student is passed to a function, and I have to find the average score of the class (or the list). let blah (class : student list) : float = match class with [] -> [] | hd :: tl -> hd ?????? So I start a standard pattern matching, get one element of the list (aka a student) but how exactly d

Where are Rust's boolean and other primitive types implemented?

I was going through the code behind some of the basic types in Rust, e.g. the pleasantly simple implementation of Option<T> or the weird macro magic behind tuple and I was able to find all of the types that I wanted in libcore. All except for one - bool. I couldn't find it anywhere else either. Where is the code behind bool in Rust? I know this is not the most novel type out there, but I was surprised I could not find it. Thanks to the answers by Francis and rodrigo, I noticed that the c

Types F# - Retrofit Record to Html Query List

In F#, is it possible to retrofit a record type to a list extracted from a web query? let customers = organization.CssSelect("div.Customers") |> List.map(fun a -> a.InnerText().Trim(), a.AttributeValue("href")) // [("1 A abcdef Alpha"); ("2 C aabbcc Bravo")] type Customer = {id:string; loc:string; code:string; name:string} so that I can access "customers.id" or "customers.name" for further processing. If so, how?

Types How can I store a generator in a struct?

I want to do this: #![feature(nll)] #![feature(generators, generator_trait)] use std::ops::Generator; struct Container<G: Generator<Yield = i32, Return = ()>> { generator: G } impl<G: Generator<Yield = i32, Return = ()>> Container<G> { pub fn new() -> Self { let q = 42; Container{ generator: || { yield 2i32 * q; } } } } fn main() {} I get this error: error[E0308]: mismatched types --> src/main.rs:12:31

Types Type in functional programming (OCaml)

I am learning functional programming and I am not understanding the types in OCaml, and I have not found anything real helpful. I have this code: let rec map2 f l1 l2 = match (l1,l2) with ([], _) -> [] | (_, []) -> [] | (x::l1s,y::l2s) -> (f x y) :: map2 f l1s l2s;; let pick n m = if n > m then (fun b x -> if b then x+1 else x*2) else (fun b x -> if b then x+2 else x*4);; map2 (pick 7 9) [true;false] [3;4;5;6];; What I find

Types Julia: get DataType from string

I want to get a type from a string (from a text parameter file). I tried something like: parse(DataType, "UInt16") or DataType("UInt16") without success. Do I have to implement my own parser or is there already one in Julia?

Julia @code_warntype warning when two different return types are expected

I made a function called jacobian that creates 4 sparse matrices with Float64 entries, make the calculations, and depending on the keyword argument stacked being true or false, returns all four separately, return A1, A2, A3, A4, or stacked as a single matrix, return vcat(hcat(A1,A2), hcat(A3,A4)). Running the function with the @code_warntype macro gives me the warning: Body::Union{NTuple{4,SparseMatrixCSC{Float64,Int64}}, SparseMatrixCSC{Float64,Int64}} 1 ─ %1 = Main.:(var"#jacobian#29"

Types Rust: Trait as a return type

Lets say there's this kind of code: trait A { fn something(&self) -> String } struct B { things: Vec<u64> } struct C { thing: Box<&dyn A> } impl A for B { ... } fn create_thing() -> B { // } impl C { pub fn new() { let thing = create_thing(); C { thing } } } My question is what exactly should be the return type of create_thing to match with Box<&dyn A> or how exactly should the returning value be wrapped to match with Box<&dyn

Types How to have an intermediate type?

Say I am compiling an AST into runnable code. Well, some of the syntax in my particular case can't be compiled into a function until some of the surrounding "functions" are evaluated after they are fully compiled. That is, some of the other functions are context sensitive, they depend on knowledge of what the surrounding functions do. So I end up needing to have an "intermediate" compilation object like this: somefunction.calls = [ { type: 'Call', pointer: function1 }, {

Problems with data types in flex

I have a problem. I'm writing a program with flex and I'm using this code: %union { int entero; char *cadena; TipoDato tipo; } This code is for my data types. I want evaluate the next line: expresion SUM expresion where SUM is the operation sum for evaluate, for example 69 + 60 When I write this if (($1.tipo == ENT) && ($3.tipo == ENT)){ $$.tipo = ENT; } else if (($1.tipo == CADEN) && ($3.tipo == CADEN)) { $$.tipo = CADEN; } else {

Types why doesn't this compile when using std::max and c++/CLI?

Can anyone please explain why the following will compile int a = aAssignments[i]->Count; int b = fInstanceData->NumRequiredEmpsPerJob[i]; fInstanceData->NumSlotsPerJob[i] = max(a,b); but fInstanceData->NumSlotsPerJob[i] = max((int)(aAssignments[i]->Count), (int)(fInstanceData->NumRequiredEmpsPerJob[i])); //why on earth does this not work? wont? The error it gives is error C2665: 'std::max' : none of the 7 overloads could convert all the argument types The variable aAssig

Go type conversions and unexported CGo types

Suppose there is CGo package with a struct defined like this: package test ... type Test struct { Field *C.C_Test } ... Now suppose that from somewhere else I get unsafe.Pointer which I know points to C_Test C structure. Do I understand correctly that there is completely no way to create new test.Test instance from the unsafe.Pointer value while being in a package other than test? Attempting to use something like &test.Test{ptr}, where ptr is unsafe.Pointer value, fails for obvious

Types Convert list to list option

It is pretty easy, my function returns a Group list but the value I try to assign the value to is of type Group list option how can I convert the Group list to Group list option. Here is my code let ParseGroupList jsonData = let parsed = GroupProvider.Parse(jsonData).JsonValue.AsArray() |> List.ofArray let groups = List.map (fun grp -> ParseGroup(grp.ToString())) parsed groups let ParseUser jsonData = let parsed = UserProvider.Parse jsonData let muta

Types How do I write higher-order functions that take polymorphic functions as arguments in Typed Racket?

For example, how can I write a version of map that will work with polymorphic functions in Typed Racket? I use a simple id function defined as: (: id : (All (A) A -> A)) (define (id x) x) When I try to map it over a list i get an error: > (map id '(1 2 3)) Type Checker: Polymorphic function `map' could not be applied to arguments: Types: (-> a b ... b c) (Listof a) (Listof b) ... b -> (Listof c) (-> a c) (Pairof a (Listof a)) -> (Pairof c (Listof c)) Arguments: (All (A)

Types Does Julia have a strict subtype operator?

Question: Does Julia have a strict subtype operator? Note: The operator <: is not a strict subtype operator, since Number <: Number evaluates to true. I am interested in an operator that would evaluate to false for Number <: Number but true for Int <: Number. Possible use case: Consider a function defined: MyFunc{T<:Union(Int, String)}(x::Array{T, 1}, y::Array{T, 1)}) Currently, the function constrains x and y to be arrays of the same type, where that type is Int, String, or

Types Assert identity of functor applications across interfaces

Suppose two simple OCaml interfaces: module type FOO = sig open Batteries module StrMap : Map.S with type key = string val foo : int StrMap.t -> int end module type BAR = sig open Batteries module StrMap : Map.S with type key = string val bar : unit -> int StrMap.t end and their trivial implementations: module Foo : FOO = struct module StrMap = Map.Make(String) let foo map = 0 end ;; module Bar : BAR = struct module StrMap = Map.Make(String) let bar () = StrM

Types Go - math.MaxInt64 and Type Inference Error

I've been working on metaprogramming involving packages and I've been running into the error constant 9223372036854775807 overflows int whenever math.MaxInt64 and math.MaxUint64 show up. I've isolated it into two cases: Valid var a int64 = math.MaxInt64 b := interface{}(int64(math.MaxInt64)) Not Valid a := math.MaxInt64 b := interface{}(math.MaxInt64) https://play.golang.org/p/U1QDmFbV29 It seems like that Go doesn't do correct type inference. Is this a bug or expected behavior? And if

Types Name an inferred type in OCaml

Assume, you have a declaration with an inferred type: let f x y = x +. y Now if you use this type in some other inferred type: let g h x = (if x > 0. then h else f) x x You obviously have a type-identity between h and f. If, however, the type of f becomes complicated and you still want it to be inferred (say you do some code-generation), the type of g easily becomes unreadable. Is there a way to introduce a type declaration in the form of: type mytype = <type of the function f ab

Types Arbitrary arrays handling F#

I'm trying to make a module in F# where i need to have some types consisting of array's of some arbirary type and with som arbitrary length. to come with an example lets say i need to make a module for arbitrary large vector calculations. then my idea is module Vector = type Vector = V of array<_> let (+) (v1:Vector) (v2:Vector) = Vector.map2 (+) V1 V2 but this is not working because the map2 function are not declaret for vectors yet and that's is the question, How do I declare the ma

Types Swifter way to check optional and then type

in Swift3 I had code like this var result: String = "" ... result = try db?.scalar(q) as! String of course that's crap and often crashes. 1) the whole thing can be nil 2) since it's an optional binding, it may not be a String This works pretty reliably if let sc = try db?.scalar(q) { print("good news, that is not nil!") if sc is String { print("good news, it is a String!") result = sc as! String } else { print("bizarrely, it was not a String. but at lea

Types Assume val and opaque type constructs in F*

I'm new to F* and although the tutorial is well-written I'm missing some good API page for reference. So I need the precise meaning for the following constructs: assume val name: type I'd say this line registers into the solver the name being used? opaque type name (...) ... What is the effect of calling a type opaque? What about the lists of parameters it may take? Please include the references you may have used to give this answer.

Types How to do an inductive definition over "booleans" in Isabelle

In Isabelle, I want to define operators that take predicates 'a => bool and modify them based on the "inductive structure of predicates". For example, one might want to compute the Disjunctive Normal Form (DNF) on these predicates, e.g. D (λ x. P x --> Q x) = (λ x. ¬ P x \/ Q x). The problem here is that bool is not an inductive datatype. I have thought of two possible solutions: Create an inductive datatype that allows me to define my operators on them. Give predicate (P::'a => bool

Types Is there a way to suppress the `rustc_on_unimplemented` message when looking for implementations of another trait that has a blanket implementation?

I have the following code: #![feature(on_unimplemented)] use std::marker::PhantomData; struct S<T>(PhantomData<T>); #[rustc_on_unimplemented(message = "T1 missing")] trait T1 {} trait T2 {} #[rustc_on_unimplemented(message = "T2 missing")] impl<T: T1> T2 for S<T> {} fn main() { wants_t2(S::<u8>(PhantomData)); } fn wants_t2<T: T2>(_: T) {} (playground) When compiling this, I get this error: error[E0277]: T1 missing --> src/main.rs:16:5 |

Types Invalid datatype function

The function getElement doesn't work. I think the problem is the cart type definition, but I don't know why. datatype element = FIRE | LAND | WATER datatype pokemon = PIKACHU | CHARMANDER | BULBASUR datatype power = int type cart = pokemon*power*element val newcart = (BULBASUR, 34, WATER) fun getElement (c: cart) = (#3)c val element = getElement newcart

Types Why is the following type declaration and/or instatiation not working in Julia 1.0?

I have a circle type struct Circle{T <: Real} # radius is a subtype of # the real number approximation types R::T # The center is a named pair of real # number approximation types C::NamedTuple{T, T} end which I would like to instantiate with circles = NamedTuple( A = Circle(1, ( 1, 1)), B = Circle(1, ( 2, 2)) ) which produces the error ERROR: LoadError: MethodError: no method matching Circle(::Int64, ::Tuple{Int64,Int64}) Closest candidates are: Circle(::T<

Types What variable type use to represent a Money in SSIS

I need to load a Money value in a variable in SSIS using a "Execute SQL Task" component. I map the return column of a SELECT to a variable. I've declared the variable "UnknownMoney" as a Double or a Single, but i always receive the error: Error: 0xC002F309 at Load Dummy vars, Execute SQL Task: An error occurred while assigning a value to variable "UnknownMoney": "The type of the value being assigned to variable "User::UnknownMoney" differs from the current variable type. Variables may not chang

Types SSAS TimeSpan in Aggregation

I have a timespan in a datawarehouse representing time spent by a user doing a task (not a time dimension, but a measure). In SQL I have this set as datetime. When this is pulled into SSAS it converts to a Date Type, and this is not usable in a cube measure aggregation. Do I need to convert the timespan into an integer (seconds), or is there a better way to do this? EDIT: I changed the data type in SQL to time(7) and it pulled into SSAS as a WChar, which is not summable.

Types Array communication: convert C doubles to chars, then java bytes to doubles

I'm having trouble sending an array of doubles from a C application to a java application (over UDP). At the moment I am casting my double data, like this char* dataChars = (char*) dataDoubles; int charsLen = sizeof(double)*doublesLen; and sending this data over UDP to java, which gets a packet containing the correct number of java double entries (ie doubles seem to be the same size in both). On the java side I recieve a byte[], then I am using: ByteArray b = ByteArray.wrap(byteData); for(

Types How to use GADTs across modules in OCaml without raising warnings?

I have two files: gadt1.ml and gadt2.ml and the second depends on the first. gadt1.ml: type never type _ t1 = A1 : never t1 | B1 : bool t1 type _ t2 = A2 : string t2 | B2 : bool t2 let get1 : bool t1 -> bool = function B1 -> true let get2 : bool t2 -> bool = function B2 -> true gadt2.ml: let get1 : bool Gadt1.t1 -> bool = function Gadt.B1 -> true let get2 : bool Gadt1.t2 -> bool = function Gadt.B2 -> true when I compile using ocaml 4.02.3 (ocamlbuild gadt2.native)

Types Why a character can be stored in and printed from a int type variable and double type variable but not from a float type variable?

Code-1: #include<stdio.h> int main() { int i; scanf("%c", &i); printf("%c", i); return 0; } Code-2: #include<stdio.h> int main() { double i; scanf("%c", &i); printf("%c", i); return 0; } Code-3: #include<stdio.h> int main() { float i; scanf("%c", &i); printf("%c", i); return 0; } In case of Code-1 & Code-2, if i give 'A' or any character as input, the character is printed as output. But in case of Code-3,

Types how to avoid unconstrained type paramameter error

I can't think of a way to get the functionality below, without the use of unconstrained types. struct Things<T> { thing: T } trait ThingActions<D> {//will be implemented for 'D's of different types fn foo(&self, data: D) {} fn bar(&self, data: D) {} } impl<T: ThingActions<D>, D> Things<T> { fn do_foos(&self, data: D) {//any D with corresponding foo can be used here self.thing.foo(data) } } impl<T: ThingActions<D>, D:

Types Why does the book How to Design Programs chose this approach on their answer sheet?

I am using the famous book How to Design Programs. More specifically, the first edition (I have the physical one). In the 6th chapter, there are some exercises with Structures. In one of them, you need to simulate traffic lights and use effects (mutation) to change them. I am referring to the exercise Exercise 6.2.5 about the function next which is suppose to give you the next color of the traffic lights. The answer sheet provided by the book is: (start 50 160) (draw-solid-disk (make-posn 25 30)

Types "Derived type is being used before it is defined" in interface block

Using cygwin64 on Windows this program won't compile: program test implicit none !define my type type myType real::foo integer::bar end type myType !define an operator for this type interface operator (>) logical function compare(a,b) type(myType),intent(in) :: a,b compare = a%foo>b%foo end function compare end interface operator (>) !simple example of operator usage type(myType) :: tfoo, tbar tfoo = card(1.,2); tbar = card(3.,

  1    2   3   4   5   6  ... 下一页 最后一页 共 9 页