Skip to main content

Questions tagged [algebraic-data-type]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer

Is there a name for this API/type design principle? (I think of it as "state hygiene")

When designing types and their APIs, I try to adhere to these simple principles (which vaguely feel like one general principle to me) as much as feasible: There is a one-to-one correspondence between ...
suushikijitsu's user avatar
1 vote
1 answer

Representing Rust enums in databases

Although I love Rust's enums (and the idea of making illegal states unrepresentable), I'm struggling to represent (ironic, yes) them in databases like PostgreSQL when the variants have data associated ...
yoshke's user avatar
  • 19
4 votes
2 answers

In the absence of code-contracts, what techniques exist to represent state invariants (e.g. "Customer with Orders loaded" with Entity Framework)?

In Entity Framework 6 and/or Entity Framework Core 3+, the code-first types generated by the scaffolding (or other code-generation tools, my preference is this T4 script) are mutable classes that do ...
Dai's user avatar
  • 680
21 votes
3 answers

What problem do algebraic data types solve?

Fair warning, I'm new to functional programming so I may hold many bad assumptions. I've been learning about algebraic types. Many functional languages seem to have them, and they are fairly useful ...
ConditionRacer's user avatar
5 votes
2 answers

How to design for good abstractions using algebraic data type?

Every now and then I have peaked at Haskell Tutorials and found the Algebraic data types quite interesting. I took their purpose to be to represent types that have completely separable states. Sadly, ...
wirrbel's user avatar
  • 3,038
1 vote
1 answer

ADT design choices

How do you go about deciding which of the following two representations (in F# syntax) is the right choice in a particular situation? type Choice = A of string | B of string Or: type ChoiceKind = A ...
Akash's user avatar
  • 155
6 votes
4 answers

What do I use for a variant in a UML class diagram?

Does standard UML specify how a variant (aka tagged union, discriminated union, sum type, etc) should be depicted in a class diagram?
Trident D'Gao's user avatar
7 votes
1 answer

I'm being warned that the Monoid I'm creating is an Orphan Instance. Is there a better way to write this functionality in?

type PromptSegment = IO (Maybe String) instance Monoid a => Monoid (IO a) where mempty = return mempty mappend = liftA2 (<>) This behaves exactly how I want for my purposes. For ...
Josiah's user avatar
  • 223
2 votes
3 answers

What procedural languages support algebraic data types? [closed]

One of the things I like about the new Apple language Swift is that it combines procedural programming with algebraic data types. What other languages do this?
John DeHope's user avatar
32 votes
1 answer

Performance of single-assignment ADT oriented code on modern CPUs

Working in immutable data with single assignments has the obvious effect of requiring more memory, one would presume, because you're constantly creating new values (though compilers under the covers ...
Jimmy Hoffa's user avatar
  • 16.1k
6 votes
2 answers

Matrix Pattern Recognition Algorithm

I am designing a logic analyzer and I would like to implement some Matrix Algorithm. I have several channels each one represented by a row in the matrix and every element in the column would be the ...
Andres's user avatar
  • 185
71 votes
8 answers

How do you encode Algebraic Data Types in a C#- or Java-like language?

There are some problems which are easily solved by Algebraic Data Types, for example a List type can be very succinctly expressed as: data ConsList a = Empty | ConsCell a (ConsList a) consmap f ...
Jörg W Mittag's user avatar