Questions tagged [algebraic-data-types]

Algebraic data types are data structures built from sums, products and recursive types, admitting an algebra. Descriptions of types given as ADTs may be manipulated symbolically to derive other related data structures. The logic for building types algebraically is related to combinatorial species in combinatorial mathematics.

On the algebraic notation for such types:

  • X for the singleton container type
  • + for choice between two types (tagged unions)
  • for the ordered product of two types
  • and a least fixed-point operator, that may be implicit.

Additionally, we have:

  • 0 for the empty type
  • 1 for unit
  • X^2 for X•X

Thus, we can describe e.g. the type of binary trees as:

  • B = 1 + X • B^2

or the type of inductive lists:

  • L = 1 + X • L

Regular data structures described in this form are the core of algebraic data types as found in Haskell or ML.

References

The Algebra of Algebraic Data Types

447 questions
0
votes
0 answers

Matlab ode solver algebreic calculation

I have an ODE model in Matlab coded as a function. I integrate the ODE's over time using ode15s. After the solver has finished, I calculate algebraically, a new variable that's a fraction of the sum of the other variables output by the model. For…
micronaut
  • 371
  • 2
  • 7
0
votes
2 answers

haskell - will pattern matching work faster for non-specific form of an algebraic data type?

i have the following type: data Tree a = Empty | Branch { key :: a, balance :: Int8, left :: Tree a, right :: Tree a, …
0
votes
4 answers

which data type correspond to 10^16 in C++?

My C++ programme may create a value until 10^16 during the run time, I tried to use "long long int" for it but it didn't work. Which data type correspond to 10^16? Thanks;
eponymous
  • 1,880
  • 5
  • 21
  • 26
0
votes
1 answer

emulate extendable algebraic types on scala

Traditional approach to algebraic types recommends something like it: sealed trait CompositeType final case class LeftBranch(left : String) extends CompositeType final case class RightBranch(right : Int) extends CompoisteType object Trivial extends…
ayvango
  • 5,627
  • 3
  • 28
  • 70
0
votes
1 answer

algebraic data type for tree

I'm trying to build a tree where its children are represented in a list. Each of the children may themselves be subtrees etc. So I go this way -- data Children a = NoChildren | Cons a (Children a) deriving (Show, Read, Ord, Eq) data Tree a =…
shashydhar
  • 771
  • 2
  • 6
  • 24
0
votes
1 answer

Haskell Algebraic types and function transformations

I've to make a function that transforms an House to an NHouse. data House = House { hworking :: Working, hfinished :: Finished} type Working = [Roof] , type Finished = [Roof] data NHouse = NHouse {rot :: [NRoof]} data NRoof = NRoof {h :: Roof,…
PablodeAcero
  • 417
  • 7
  • 20
0
votes
2 answers

How to construct binary tree from algebraic expression

In my exam I got this expression and failed to construct binary tree. what would be the solution? (5a-3b)^2*(3a+5b)^3 I drew the tree from above expression like * / \ / \ ^ \ / \ \ …
Iqbal
  • 235
  • 8
  • 19
0
votes
1 answer

How to find the minimum using algebraic query language

I need to find the cheapest Honda Civic sold in this table Sell(DName, Make, ModelNum, Price) There are other tables, but I am assuming that no other manufacturers have named their make Civic. So I'm looking to find the lowest price that is of Make…
Iuli
  • 111
  • 1
  • 3
  • 12
-1
votes
1 answer

How can you create a list comprising of calculations on each item of another list in Haskell?

I'm trying to make a function working out (and then outputting as a String) the difference between two elements in a list - 1st and 2nd, then 2nd and 3rd, and so on - I think I'm giving it a good go, but I currently keep running into error…
Alex
  • 277
  • 1
  • 2
  • 12
-1
votes
1 answer

Why is Haskell lookup function causing Non-Exhaustive pattern error on custom data type?

Anyone know why this is causing the error Non-exhaustive patterns in function getCityPopulation? type Name = String type Coordinates = (Int, Int) type Pop = Int type TotalPop = [Pop] type City = (Name, (Coordinates, TotalPop)) testData ::…
-1
votes
1 answer

Complex Sum Type in Scala

I have the following Type that i need to model: sealed trait FieldType case object INT extends FieldType case object UINT extends FieldType case object FLOAT extends FieldType case object DOUBLE extends FieldType case object BOOL extends…
MaatDeamon
  • 7,821
  • 5
  • 46
  • 96
-1
votes
2 answers

Transformation of two integers into a double in Java

This is the task: Implement a static-public method named "createDouble" in the class "Functionality.java". The method gets two integer values a and b as input and should transform them to a double value and return it as follows: The first input…
-1
votes
1 answer

Pattern matching Over A Nested Data Constructor

For the following code I keep on getting a compiler error because I am writing (List _) and it is trying to pattern match over the list. How can I fix tihs? data List a = Cons a (List a) | Empty instance Monad List where Empty >>= _ = Empty …
barskyn
  • 341
  • 1
  • 2
  • 10
-1
votes
1 answer

Haskell How to get the difference between 2 different data types in a list of tuples?

I was wondering if there is an easy way to get the difference between 2 data types in Haskell, in a list of tuples. Let's says I define 2 data types : type Name = String type Age = String type Color = String type Size = Int data Animal = Animal…
Caro
  • 21
  • 7
-1
votes
1 answer

Haskell How to pass many data type arguments to a function?

I have defined two data type. type LastName = String type FirstName = String type CodeP = Int type CodeS = String type CodeI = Int type GroupNb = Int type Session = Int Data Inscription = Inscription CodeS GroupNb Session deriving (Show, Eq) Data…
Caro
  • 21
  • 7
1 2 3
29
30