recursive-datastructures

What is the difference between Fix, Mu and Nu in Ed Kmett's recursion scheme package

做~自己de王妃 提交于 2020-06-09 09:25:54
问题 In Ed Kmett's recursion-scheme package, there are three declarations: newtype Fix f = Fix (f (Fix f)) newtype Mu f = Mu (forall a. (f a -> a) -> a) data Nu f where Nu :: (a -> f a) -> a -> Nu f What is the difference between those three data types? 回答1: Mu represents a recursive type as its fold, and Nu represents it as its unfold. In Haskell, these are isomorphic, and are different ways to represent the same type. If you pretend that Haskell doesn't have arbitrary recursion, the distinction

Hierarchical roll-up in SQL accounting system

▼魔方 西西 提交于 2020-05-17 04:50:05
问题 I'm trying to make annual reports (Balance Sheet and Profit & Loss) from general journal entries in an accounting system. The general journal table (simplified) includes: CREATE TABLE `sa_general_journal` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `Date` timestamp NOT NULL DEFAULT current_timestamp(), `Item` varchar(1024) NOT NULL DEFAULT '', `Amount` decimal(9,2) NOT NULL DEFAULT 0.00, `Source` int(10) unsigned NOT NULL, `Destination` int(10) unsigned NOT NULL, PRIMARY KEY (`ID`), KEY

Recursively dir() a python object to find values of a certain type or with a certain value

谁说胖子不能爱 提交于 2020-02-27 05:27:12
问题 I have a complex Python data structure (if it matters, it's a large music21 Score object) which will not pickle due to the presence of a weakref somewhere deep inside the object structure. I've debugged such problems with the stack trace and python debugger before, but it's always a big pain. Is there a tool which runs dir() recursively on all attributes of an object, finding objects hidden in lists, tuples, dicts, etc., and returns those that match a certain value (a lambda function or

Need direction about Binary Search Tree implementation in Objective-C

被刻印的时光 ゝ 提交于 2020-01-06 06:25:19
问题 I have a partial implementation of a binary tree that doesn't work properly. I believe I am missing fundamental knowledge about struct memory management in objective-c but not sure what it is(besides malloc). When I try to create a new tree node based on a struct I get Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) which led me to believe I didn't create a memory location for this struct pointer. What is the proper way of doing this in Objective-C? (Code in below) Thank you for taking the

Representing a directory tree as a recursive list

我与影子孤独终老i 提交于 2020-01-03 08:36:07
问题 I am stuck with a certain task. What I want is a function that, given a directory path, would return a recursive-list as an output. The output should be of the form myList$dir$subdir$subdir$fullFilePath So basically I want to represent a directory tree as a certain list. I obtain all the files, get all the subdirectories for each of the file, but I am stuck as to how to throw it all into a list with multiple levels. 回答1: Here is a solution using recursion: tree.list <- function(file.or.dir) {

How to create a recursive data structure value in (functional) F#?

a 夏天 提交于 2020-01-01 09:10:12
问题 How can a value of type: type Tree = | Node of int * Tree list have a value that references itself generated in a functional way? The resulting value should be equal to x in the following Python code, for a suitable definition of Tree: x = Tree() x.tlist = [x] Edit : Obviously more explanation is necessary. I am trying to learn F# and functional programming, so I chose to implement the cover tree which I have programmed before in other languages. The relevant thing here is that the points of

create dynamic nested json objects using recursive

烈酒焚心 提交于 2019-12-31 04:10:14
问题 I have following JSON. [{ "ID": "Root_1", "Name": "Root_1", "ParentID": "", "Sequent": 1 }, { "ID": "Root_2", "Name": "Root_2", "ParentID": "", "Sequent": 2 }, { "ID": "Root_1_Sub_1_Child_1", "Name": "Root_1_Sub_1_Child_1", "ParentID": "Root_1_Sub_1", "Sequent": 1 }, { "ID": "Root_1_Sub_1_Child_2", "Name": "Root_1_Sub_1_Child_2", "ParentID": "Root_1_Sub_1", "Sequent": 2 }, { "ID": "Root_1_Sub_1", "Name": "Root_1_Sub_1", "ParentID": "Root_1", "Sequent": 1 }] I want to change my JSON to as

Recursive schema with avro (SchemaBuilder)

孤人 提交于 2019-12-25 03:53:40
问题 Is it possible to make an avro schema which is recursive, like Schema schema = SchemaBuilder .record("RecursiveItem") .namespace("com.example") .fields() .name("subItem") .type("RecursiveItem") .withDefault(null) // not sure about that too... .endRecord(); I get a StackOverflowError when using it like that: static class RecursiveItem { RecursiveItem subItem; } RecursiveItem item1 = new RecursiveItem(); RecursiveItem item2 = new RecursiveItem(); item1.subItem = item2; final DatumWriter

How can I iterate over a quadruple linked 2-dimensional grid of data as if it were a 2-dimensional array?

烂漫一生 提交于 2019-12-24 19:24:31
问题 How can I iterate over a quadruple linked 2-dimensional grid of data as if it were a 2-dimensional array? My grid structure is: typedef bool tile; struct BLOCK; typedef struct BLOCK block; struct BLOCK { const block * to_the_left; const block * above; const block * to_the_right; const block * below; tile data; }; typedef struct { const block * start; } map; I need to be able to iterate over this grid like it is a 2-dimensional array so I can display tiles of the map on the screen centering

Instantiate types from recursive type grammar

我怕爱的太早我们不能终老 提交于 2019-12-24 08:46:45
问题 Given this recursive type grammar: case class Fix[F[_]](out: F[Fix[F]]) type FieldValue = Seq[String] :+: String :+: Int :+: Long :+: CNil type FieldLeaf[F] = FieldValue :+: SubField[F] :+: CNil type SubField[F] = Seq[F] type Field0[F] = (String, FieldLeaf[F]) type Field = Fix[Field0] And instances of Seq[Field] Is it feasible to instantiate concrete classes from the type grammar? I.e: def instantiate[T](fields:Seq[Field]):Option[T] = .... case class Person(id:Long, name:String) val fields