record

Record-type recursive member functions and the “rec” keyword

允我心安 提交于 2019-12-04 22:20:52
I've always believed that in F# we needed to use the rec keyword for every recursive function, for example: let rec factorial = function | 0 -> 1 | k when k > 0 -> k * (factorial (k - 1)) | failwith "oops!" Today I was playing around with F# and I came up with a code similar to the following: let MyRecordType = { Something : float; SomethingElse : int } with static member factorial = function | 0 -> 1 | k when k > 0 -> k * (MyRecordType.factorial (k - 1)) | failwith "oops!" As you see, I've just defined a recursive function, but I made what at first seemed like a mistake: I forgot to declare

How to use high order functions to filter and match on options fields in a record

醉酒当歌 提交于 2019-12-04 19:33:46
So a bit of context is required just to understand my issue. In an RPG, I consider the equipment as a record with optional fields, which means, while they're None that nothing was attributed yet. Equipment is constructed by the game items of the game that represents either weaponry or character protection (helmets and etc) which will be seen in the snippet below. The functionalities are removed and the domain model reduced to make it easier to read. type ConsummableItem = | HealthPotion | ManaPotion type Weaponry = | Sword | Spear | BattleAxe type CharaterProtection = | Helmet | Gloves | Boots

Haskell — any way to qualify or disambiguate record names?

ぐ巨炮叔叔 提交于 2019-12-04 17:51:52
问题 I have two data types, which are used for hastache templates. It makes sense in my code to have two different types, both with a field named "name". This, of course, causes a conflict. It seems that there's a mechanism to disambiguate any calls to "name", but the actual definition causes problems. Is there any workaround, say letting the record field name be qualified? data DeviceArray = DeviceArray { name :: String, bytes :: Int } deriving (Eq, Show, Data, Typeable) data TemplateParams =

How to use record to loop a ref cursor?

淺唱寂寞╮ 提交于 2019-12-04 16:12:57
I want to write PL/SQL to test a function in a package. The package defines a cursor type TYPE ref_cursor IS REF CURSOR; I want to define a record based on that type. My code is: DECLARE cur PACKAGE_NAME.ref_cursor; rec cur%ROWTYPE; why is last line not correct? You can't define a record type based on a weakly-typed REF CURSOR. Since the cursor type defined in the package can be used to return data from an arbitrary query with arbitrary columns, the PL/SQL compiler can't determine an appropriate record type to fetch the data into. If you know the actual data being returned from the function,

Delphi: Record constructor vs factory function

非 Y 不嫁゛ 提交于 2019-12-04 16:09:46
问题 So what will be the preferred way of initializing records? With a 'factory function': TMyRecord = record valueX: integer; valueY: integer; end; function MyRecord(const AValueX, AValueY: integer): TMyRecord; begin result.valueX := AValueX; result.valueY := AValueY; end; var myrec: TMyRecord; begin myrec := MyRecord(1, 2); end; or a constructor: TMyRecord = record valueX: integer; valueY: integer; constructor Create(const AValueX, AValueY: integer); end; constructor TMyRecord.Create(const

SSIS transactional data (different record types, one file)

不问归期 提交于 2019-12-04 13:22:28
An interesting one, we're evaluating ETL tools for pre-processing statement data (e.g. utility bills, bank statements) for printing. Some of the data comes through in a single flat file, with different record types. e.g. a record type with "01" as the first field will be address data. This will have name and address fields. A record type with "02" will be summary data, with balances and totals. Record type "03" will be a line item on the statement. Each statement will have one 01 and 02 records, and multiple 03 records. I could pre-parse the file and split into 3 files for loading into a table

Delphi - Invoke Record method per name

依然范特西╮ 提交于 2019-12-04 13:03:00
问题 I wrote a scriptlanguage for my applications and my goal is to make it possible to publish any type from delphi in the script. I use rtti to automatize this task. For any instance type like classes I use the following code to find and call a method from script. var Info : TRttiType; Meth : TRttiMethod; Param : TArray<TValue>; Result : TValue; AnyClass : TClass; begin ... Info := RttiContext.GetType(AnyClass); Meth := Info.GetMethod('AMethod'); Setlength(Param, 1); Param[0] := TValue.From

Constructor on public record type?

这一生的挚爱 提交于 2019-12-04 09:55:37
Let's say I want a record type such as: type CounterValues = { Values: (int) list; IsCorrupt: bool } The thing is, I want to create a constructor that converts the list passed of integers to a new list which has no negative values (they would be replaced by 0s), and have IsCorrupt=true only if there were negative values found at construction time. Is this possible with F#? For now, this is what I've done, using properties (but, meh, it's not very F#-ish and it calls ConvertAllNegativeValuesToZeroes() at the getter every time so it's not very efficient): type CounterValues (values: (int) list)

android AudioRecord amplitude reading from MIC

懵懂的女人 提交于 2019-12-04 09:20:04
问题 I am trying to record the sound from the MIC and draw a live graph. I am able to record and draw the graph. The problem is the values that are recorded using the code below are not accurate for example ... the image below is what i get when there is no sound at all present. I have seen examples using the fft but I am noot sure if that will be of any help in my case as I am trying to draw a time domain graph and I see no purpose to convert it to frequency domain (for now). Others are using

Nesting Avro schemas

人走茶凉 提交于 2019-12-04 06:00:09
According to this question on nesting Avro schemas, the right way to nest a record schema is as follows: { "name": "person", "type": "record", "fields": [ {"name": "firstname", "type": "string"}, {"name": "lastname", "type": "string"}, { "name": "address", "type": { "type" : "record", "name" : "AddressUSRecord", "fields" : [ {"name": "streetaddress", "type": "string"}, {"name": "city", "type": "string"} ] }, } ] } I don't like giving the field the name address and having to give a different name ( AddressUSRecord ) to the field's schema. Can I give the field and schema the same name, address ?