For months I have been wondering how to abstract a "class" meaning "a set of reusable functions" in Haskell. Finally I found a sample solution:
class Graph a where
newGraph :: a
hasVertex :: a -> Int -> Bool
hasEdge :: a -> (Int,Int) -> Bool
addEdge :: a -> (Int,Int) -> a
addVertex :: a -> a
removeEdge :: a -> (Int,Int) -> a
removeVertex :: a -> Int -> a
inDegree :: a -> Int -> Int
outDegree :: a -> Int -> Int
Source: wsaleem/jambrothers, https://stackoverflow.com/questions/43656453/a-generic-way-to-convert-between-types-in-haskell
The thing to note here is that the "class" in the code does not refer to class as a data type, but rather class as a "typeclass".
Small executables
$ ghc -o hello hello.hs
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
700 hello
476 hello-small
Add the -dynamic flag for a dynamically linked RTS:
$ ghc -dynamic -o hello hello.hs
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
24 hello
16 hello-small
For comparison with C:
$ gcc hello.c -o hello
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
12 hello
8 hello-small
Source: Caleb Case and Nybble, https://stackoverflow.com/a/3098498