Haskell tutorial for C programmers
haskell.org
Haskell tutorial for C programmers
1–10 of 56 posts
Re: Haskell tutorial for C programmers
#2For anyone who needs a refresher on DFA, Stanford's CS143 compilers class course materials are up on Coursera (https://www.coursera.org/course/compilers), and pretty helpful.
Re: Haskell tutorial for C programmers
#3Re: Haskell tutorial for C programmers
#4Er, you could define mergesort using templates in c++ and it would work pretty much the same.
Re: Haskell tutorial for C programmers
#5>What this means is that existing sort functions such as mergeSort and quickSort would need to be rewritten to sort values of the new type. In constrast, here is the type of mergeSort in Haskell mergeSort :: Ord a => [a] -> [a] Er, you could define mergesort using templates in c++ and it would work pretty much the same.
Re: Haskell tutorial for C programmers
#6>What this means is that existing sort functions such as mergeSort and quickSort would need to be rewritten to sort values of the new type. In constrast, here is the type of mergeSort in Haskell mergeSort :: Ord a => [a] -> [a] Er, you could define mergesort using templates in c++ and it would work pretty much the same.
How do you express the Ordinality constraint in C++?
The advantage that Haskell's typeclasses have over either Java or C++ is that the types aren't closed. I can define a new typeclass and tell the compiler that a type you defined is a member of that class at any point. In Java, if you don't define that your type is Comparable, there's nothing that I, as a consumer of your type, can do about it.
Re: Haskell tutorial for C programmers
#7>What this means is that existing sort functions such as mergeSort and quickSort would need to be rewritten to sort values of the new type. In constrast, here is the type of mergeSort in Haskell mergeSort :: Ord a => [a] -> [a] Er, you could define mergesort using templates in c++ and it would work pretty much the same.
How do you express the Ordinality constraint in C++?
Re: Haskell tutorial for C programmers
#8>What this means is that existing sort functions such as mergeSort and quickSort would need to be rewritten to sort values of the new type. In constrast, here is the type of mergeSort in Haskell mergeSort :: Ord a => [a] -> [a] Er, you could define mergesort using templates in c++ and it would work pretty much the same.
How do you express the Ordinality constraint in C++?
Re: Haskell tutorial for C programmers
#9Earlier quoted context omitted.
How do you express the Ordinality constraint in C++?
Concepts will accomplish this when they finally make it into the standard.
The error you get if you try to sort a vector with an unordered type is relatively easy to read:
main.cpp: In instantiation of 'void merge_sort(std::vector&) [with T = type]':
main.cpp:45:17: required from here
main.cpp:30:5: error: static assertion failed: Element type is not sortable
static_assert( concept::is_ord(), "Element type is not sortable" );
^