336 karma · joined October 26, 2015
This[1] is a good paper about monads in functional programming. It reads quite similarly to a monad tutorial, but with a little more formality.
As for actual category theory, I've enjoyed the first few chapters of "Algebra: Chapter 0", by Aluffi.
If you're after more type theory, the usual recommendations are "Types and Programming Languages", by Pierce, and "Software Foundations", also by Pierce.
[1] http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/ba...
If you wanted to prove that a list was sorted, you'd write another datatype:
IsSorted : Ord a => List a -> Type
which represents the proposition that the input list is sorted. You could encode this by requiring that any new element in the list is either the first element, or less than or equal to the previous element. Then, your sorting function could return a dependent pair: (l : List a ** IsSorted l)
which can be read as the list, accompanied by a proof that it is, in fact, sorted. Since your `IsSorted` type requires that the list is sorted, via construction, you won't be able to supply the output of the function unless your code is correct (or you use `believe_me`!).The compiler doesn't generally come up with counterexamples for you; with this style, if the proof isn't complete, it won't compile.
The key here is that `add` is not a function `Nat -> Nat -> Nat`, it is a function `(a : Nat) -> (b : Nat) -> LT a b -> Nat`. There are just some compiler features that allow you to avoid having to write out the full `LT a b` proof each time you want to add things!
foo x = case x of
pattern1 -> ...For example, it's quite obvious what the intent of this Idris function is: `f : Vect n (Vect m a) -> Vect m (Vect n a)` (where `Vect` is the type of lists of a given length).
fac = \n -> product [1..n]
The recursive one is also much the same as a Haskell one, but Q is hardly built around idiomatic recursion. let x : u32 = 0;
In Haskell, it's used for temporary definitions, or pure definitions in do blocks: let f = \x -> x + 1 in f 2There's quite a lot more to politics, and politics in democracy, than just the act of voting.