scala,enumeration,case-class,algebraic-data-types

You would need to create a singleton companion object MeasureType and write withValue method by hand using pattern matching on the argument. object MeasureType { def withValue(val : String) : MeasureType = val match { case "Hour" => Hour case "Day" => Day case "Week" => Week case "Month" =>...

haskell,functional-programming,lambda-calculus,algebraic-data-types,scott-encoding

If the Wikipedia article is correct, then data Tree a = Node (List (Tree a)) | Leaf a has Scott encoding node = λ a . λ node leaf . node a leaf = λ a . λ node leaf . leaf a It looks like the Scott encoding is...

serialization,algebraic-data-types,discriminated-union

Protocol Buffers version 2.6.0 added support for tagged unions in the form of the oneof declaration, but it looks like protobuf-net has not been updated recently so I'm guessing it doesn't support this yet. Cap'n Proto is used in production in a lot of places (e.g. CloudFlare), but it's true...

scala,type-systems,algebraic-data-types

You can see the source code for List here. There's nothing special going on to do with base cases, it's just that List is declared as sealed, and then there are only two classes extending it: sealed abstract class List[+A] ... case object Nil extends List[Nothing] { ... } final...

haskell,algebraic-data-types,parametric-polymorphism

If you look at the inferred type for decode_encode :t decode_encode > decode_encode :: ((BTAlg BT -> (BTAlg z -> z) -> z) -> t) -> t it's clear that GHC has lost quite a bit of polymorphism. I'm not completely sure of the details here—this code requires ImpredicativeTypes to...

haskell,fold,type-mismatch,algebraic-data-types

A proper definition should consist of a pair of mutually recursive functions, one for folding trees and one for folding forests (lists of trees): foldtree :: (a -> c -> b) -> (b -> c -> c) -> c -> Treeof a -> b foldtree f g a (Node label...

list,haskell,compiler-flags,algebraic-data-types,gadt

It looks like you're trying to restrict lists to only be able to hold values that implement Eq, and you can't do that without extensions. You can, however, tell the compiler how to compare two List as when a has a type that implements Eq. There are two easy ways...

recursion,ocaml,algebraic-data-types

Ultimately, the implementation for a pair of mutually recursive datatypes for a red black tree was: type ’a black_node = Leaf | RNode of ’a * ’a red_node * ’a red_node | BNode of ’a * ’a black_node * ’a black_node and ’a red_node = RedNode of ’a * ’a...

javascript,jquery,node.js,promise,algebraic-data-types

Pacta's interface is "algebraic," but I don't have any experience with that paradigm. ADTs are type theory constructs that represent nested data types, like a Promise for Integer. They are heavily used in functional programming, a flavour where you always know the types of your expressions and values. There...

haskell,tuples,algebraic-data-types,value-constructor

Well, coneptually there indeed is no difference and in fact other languages (OCaml, Elm) present tagged unions exactly that way - i.e., tags over tuples or first class records (which Haskell lacks). I personally consider this to be a design flaw in Haskell. There are some practical differences though: Laziness....

haskell,tree,binary-tree,huffman-coding,algebraic-data-types

You're not constructing the Huffman tree correctly. The process is supposed to go like this: Turn all the source symbols into single-element huffman trees Pair each source symbol up with its frequency into a big list of tree/frequency pairs. If there is just one tree/frequency pair left, that tree is...

haskell,types,monads,algebraic-data-types,io-monad

You want something like newtype CWIO a = CWIO { unCWIO :: CWorld -> (a, CWorld) } which will allow you to define the appropriate instances and to use CWIO and unCWIO to move back and forth between wrapped CWIO computations and the unwrapped underlying functions. newtype is a variant...

haskell,abstract-data-type,algebraic-data-types,gadt

There is no independent concept named generalized abstract data type. The phrase "generalized abstract data type" is sometimes incorrectly used for generalized algebraic data type. This mistake arises because both "algebraic data type" and "abstract data type" are abbreviated as "ADT".

vector,linked-list,algebraic-data-types,idris

It doesn't do anything to optimise Vector lookups (at the time of writing this answer, at least). This isn't because of any difficulty in doing it, really, but more because I would rather have some kind of general framework for writing this kind of optimisation than hard coding lots of...

algebraic-data-types,idris,formal-verification

The induction tactic can only be used on types that were declared with %elim. Some people feel that Idris should be automatically generating eliminators whenever possible, but there would appear to be some technical difficulties with that. Could anybody give an example for, say, the aforementioned All? As far as...

scala,pattern-matching,abstract-data-type,algebraic-data-types,higher-kinded-types

Unfortunately, you cannot do what you want. The problem is that it is not enough that scalac know that Sig#None <: Sig#Option[A], it must be able to verify that the value it is passing to unapply is, in fact, Sig#None. This works for scala.Option, because the compiler can generate an...

haskell,functional-programming,complexity-theory,algebraic-data-types

It's because of immutable state. A list is an object + a pointer, so if we imagined a list as a Tuple it might look like this: let tupleList = ("a", ("b", ("c", []))) Now let's get the first item in this "list" with a "head" function. This head function...