Neon.Class
- Package
- purescript-neon
- Repository
- tfausak/purescript-neon
Every type class in Neon starts with "Has". There are two reasons for this:
It avoids collisions with data types. The
HasMaptype class is distinct from theMapdata type.Each type class has one function, so naming the class after that function results in better error messages.
newtype MyArray a = MyArray (Array a) MyArray [1, 2, 3] :map (_ + 1) -- Error found: -- No type class instance was found for -- Neon.Class.HasMap.HasMap MyArray
Re-exports from Neon.Class.HasAdd
Re-exports from Neon.Class.HasAnd
#HasAnd Source
class HasAnd a whereRepresents types that can be conjoined. This is also known as logical conjunction.
true :and false -- false
Some types can't be conjoined per se but it is still useful to be able to
use the && operator with them. For example, you can and two arrays
together to get their intersection.
[1, 2, 3] :and [2, 3, 4] -- [2, 3]
For integers, and is bitwise.
5 :and 3 -- 3
The instance for functions is perhaps the hardest to understand. Combining
two functions with and returns a new function that calls each function
and then ands the results together.
even :and odd -- \ x -> (even x) :and (odd x)
(even :and odd) 3 -- false
Members
and :: a -> a -> a
Instances
Re-exports from Neon.Class.HasApply
#HasApply Source
class HasApply a whereRepresents types that can be applied from within a container. In other words, given both a function and a value in a container, apply the function to the value and return the result in a container. This is also known as an applicative functor.
[3, 4] :apply [(_ + 2), (_ * 2)] -- [5, 6, 6, 8]
Just 2 :apply (Just (_ + 1)) -- Just 3
Members
apply :: forall c b. a (b -> c) -> a b -> a c
Instances
Re-exports from Neon.Class.HasBottom
Re-exports from Neon.Class.HasChain
Re-exports from Neon.Class.HasCompare
#HasCompare Source
class (HasEqual a, HasGreater a, HasLess a) <= HasCompare a whereRepresents type that have a total order.
2 :compare 1 -- GT
2 :compare 2 -- EQ
2 :compare 3 -- LT
Members
Instances
Re-exports from Neon.Class.HasDivide
Re-exports from Neon.Class.HasEqual
#HasEqual Source
class HasEqual a whereRepresents types that can be equal to each other.
equal 1 2 -- false
equal 3 3 -- true
Members
Instances
Re-exports from Neon.Class.HasFilter
Re-exports from Neon.Class.HasFromArray
#HasFromArray Source
class HasFromArray a b whereRepresents types that can be converted from an array.
fromArray [1] :: List Int -- Cons 1 Nil
fromArray [1] :: Maybe Int -- Just 1
fromArray ['a', 'b'] :: String -- "ab"
Members
Instances
HasFromArray a (Array a)HasFromArray a (List a)HasFromArray a (Maybe a)HasFromArray Char String
Re-exports from Neon.Class.HasFromInt
#HasFromInt Source
class HasFromInt a whereRepresents types that can be converted from integers. This is typically used for enumerations.
fromInt 1 :: Maybe Bool -- Just true
fromInt 2 :: Maybe Bool -- Nothing
Members
Instances
Re-exports from Neon.Class.HasGreater
#HasGreater Source
class HasGreater a whereRepresents types where one value can be greater than another.
2 :greater 1 -- true
1 :greater 2 -- false
Members
Instances
(HasEqual a, HasGreater a) => HasGreater (Array a)HasGreater BooleanHasGreater CharHasGreater Int(HasEqual a, HasGreater a) => HasGreater (List a)HasGreater NumberHasGreater OrderingHasGreater String
Re-exports from Neon.Class.HasInspect
#HasInspect Source
class HasInspect a whereRepresents types that can be converting to a string. This is typically
used for debugging. The result of inspect x should be a valid PureScript
expression.
inspect 123 -- "123"
inspect (Just 123) -- "Just (123)"
The instance for functions and objects do not return valid expressions. This is because there is no way in general to generate an expression for them.
inspect identity -- "{- Function -}"
inspect {} -- "{- Object -}"
Members
Instances
Re-exports from Neon.Class.HasLess
#HasLess Source
class HasLess a whereRepresents types where one value can be less than another.
1 :less 2 -- true
2 :less 1 -- false
Members
Instances
Re-exports from Neon.Class.HasMap
Re-exports from Neon.Class.HasMultiply
#HasMultiply Source
class HasMultiply a whereRepresents values that can be multiplied together. This is also known as a near-ring.
2 :multiply 3 -- 6
Members
multiply :: a -> a -> a
Instances
Re-exports from Neon.Class.HasNot
#HasNot Source
class HasNot a whereRepresents types can be negated. This is known as negation.
not false -- true
The instance for functions is a little tricky. Calling not on a function
returns a new function that calls the original function and then nots
the result.
not even -- \ x -> not (even x)
(not even) 3 -- true
Members
not :: a -> a
Instances
Re-exports from Neon.Class.HasOne
Re-exports from Neon.Class.HasOr
#HasOr Source
class HasOr a whereRepresents types that can be disjoined. This is also known as logical disjunction.
true :or false -- true
Some types can't be disjoined per se but it is still useful to be able to
use the || operator with them. For example, you can or two arrays
together to get their union.
[1, 2, 3] :or [2, 3, 4] -- [1, 2, 3, 4]
For integers, or is bitwise.
5 :or 2 -- 7
The instance for functions is perhaps the hardest to understand. Combining
two functions with or returns a new function that calls each function
and then ors the results together.
even :or odd -- \ x -> (even x) :or (odd x)
(even :or odd) 3 -- true
Members
or :: a -> a -> a
Instances
Re-exports from Neon.Class.HasPower
Re-exports from Neon.Class.HasPure
Re-exports from Neon.Class.HasReduce
Re-exports from Neon.Class.HasRemainder
#HasRemainder Source
class HasRemainder a whereRepresents types that are divisible.
7 :remainder 2 -- 1
7.0 :remainder 2.0 -- 1.0
Members
remainder :: a -> a -> a
Instances
Re-exports from Neon.Class.HasSubtract
#HasSubtract Source
class HasSubtract a whereRepresents types that can be subtracted from each other.
3 :subtract 2 -- 1
Members
subtract :: a -> a -> a
Instances
(HasEqual a) => HasSubtract (Array a)HasSubtract Int(HasEqual a) => HasSubtract (List a)HasSubtract Number
Re-exports from Neon.Class.HasToArray
#HasToArray Source
class HasToArray a b whereRepresents types that can be converted to an array.
toArray (Cons 1 Nil) :: Array Int -- [1]
toArray (Just 1) :: Array Int -- [1]
toArray "ab" :: String -- ['a', 'b']
Members
Instances
HasToArray (Array a) aHasToArray (List a) aHasToArray (Maybe a) aHasToArray String Char
Re-exports from Neon.Class.HasToInt
Re-exports from Neon.Class.HasTop
Re-exports from Neon.Class.HasTraverse
#HasTraverse Source
class HasTraverse t whereRepresents data structures that can be traversed from left to right.
Unlike Reduce, these structures can be traversed while keeping their
shape.
[1, 2] :traverse (\ x -> x :inspect :Just) -- Just ["1", "2"]
Members
Instances
Re-exports from Neon.Class.HasZero
- Modules
- Neon
- Neon.
Class - Neon.
Class. HasAdd - Neon.
Class. HasAnd - Neon.
Class. HasApply - Neon.
Class. HasBottom - Neon.
Class. HasChain - Neon.
Class. HasCompare - Neon.
Class. HasDivide - Neon.
Class. HasEqual - Neon.
Class. HasFilter - Neon.
Class. HasFromArray - Neon.
Class. HasFromInt - Neon.
Class. HasGreater - Neon.
Class. HasInspect - Neon.
Class. HasLess - Neon.
Class. HasMap - Neon.
Class. HasMultiply - Neon.
Class. HasNot - Neon.
Class. HasOne - Neon.
Class. HasOr - Neon.
Class. HasPower - Neon.
Class. HasPure - Neon.
Class. HasReduce - Neon.
Class. HasRemainder - Neon.
Class. HasSubtract - Neon.
Class. HasToArray - Neon.
Class. HasToInt - Neon.
Class. HasTop - Neon.
Class. HasTraverse - Neon.
Class. HasZero - Neon.
Data - Neon.
Effect - Neon.
Helper - Neon.
Operator - Neon.
Primitive - Neon.
Primitive. Char - Neon.
Primitive. Function - Neon.
Primitive. Int - Neon.
Primitive. Number