DAY 10
0
Software Development

yo, what's up

## What's Algebraic structure?

In mathematics, and more specifically in abstract algebra, an algebraic structure on a set A (called carrier set or underlying set) is a collection of finitary operations on A ; the set A with this structure is also called an algebra. - James Sinclair

## Example

### method (HM Type signature)

``````equals :: Setoid => a -> a -> Boolean
``````

``````equals :: Setoid a => a ~> a -> Boolean
``````

`~>` 的意思就是 `a` 必須要有 `equal` 這個 method，而 `~>` 右方才為 `equal` 的 signature.

### law

1. reflexivity:

``````a.equals(a) === true
``````

2. symmetry

``````a.equals(b) === b.equals(a)
``````

3. transitivity

``````a.equals(b) && b.equals(c) === a.equals(c)
``````

### implement

``````import * as R from 'ramda';

const Setoid = (val) => ({
val,
equals: o => R.equals(val, o.val),
inspect: () => `Setoid(\${val})`
})

Setoid('Functional Progamming').equals(Setoid('Functional Progamming')) // true

Setoid('Functional Progamming').equals(Setoid('Object Oriented Progamming')) // false
``````