he Haskell functions div and ^ are partial, meaning they can crash with a so-called imprecise exception (an exception that is not visible in the type, also sometimes called IO exceptions).
partial functions
he Haskell functions div and ^ are partial, meaning they can crash with a so-called imprecise exception (an exception that is not visible in the type, also sometimes called IO exceptions).
partial functions
We can use newtype whenever we define a datatype with a single constructor that has a single-value - intuitively, whenever we simply "wrap" an underlying type.
Brug gerne newtype når vi bare skal "wrappe" en underliggende datatype (i det her tilfælde Double) med en anden datatype (som her er Q der er vores value constructor til højre for =)
Note that we do not actually use the type parameter unit in the right hand side of the definition. It is a phantom type, that exists only at compile-time, in order to constrain how Qs can be used. When constructing a value of type Q, we can instantiate that unit with anything we want. For example
Vigtig: forklaring af phantom type
Specifically, we now define a type constructor Q for representing a quantity of some unit:
Fra Learn You Haskell...: "Once again, it's very important to distinguish between the type constructor and the value constructor. When declaring a data type, the part before the = is the type constructor and the constructors after it (possibly separated by |'s) are value constructors." Så Q til vnstre er type constructoren med type parameteret unit, og Q til højre er valu constructor, som tager en Double
irst, we define some types that do not have constructors:
Husk at value constructors for en type er til højre for =
ee how the fmap method turns an f a into an f b, intuitively changing the a values to b values. That means f by itself is not a type - it must be applied to a type, and hence is a type constructor.
Faktisk rigtig fin forklaring for at forstå forskel på type og type constructor
One interesting detail is that Functor instances are not defined for types, but for type constructors. Se
Vigtigt!
import Test.Tasty (defaultMain)
Her importerer vi kun defaultMain funktionen fra modulet