An interesting aspect of MirageOS is how it approaches building for different platforms (unix, xen). You write your code to work with a specific interface for networking, files and such and at build time select the concrete implementation. So you can test in your normal unix environment and when satisfied can build a Xen kernel. Only the code that's actually used is included so the resulting binaries are pretty small for a kernel.
The mechanism used for the compile time selection of concrete module implementations is OCaml functors (not to be confused with Haskell functors). Few other languages have this feature and it leads to an interesting programming style. For example if you want to have a map with keys of your custom type you define a module and say type t = my_type, add a compare function to it and then say module MyMap = Map.Make(MyModule), the MyMap module will then have all the map functions specialized for your type.
3 comments
1 u/pminten [OP] 11 Aug 2015 11:42
An interesting aspect of MirageOS is how it approaches building for different platforms (unix, xen). You write your code to work with a specific interface for networking, files and such and at build time select the concrete implementation. So you can test in your normal unix environment and when satisfied can build a Xen kernel. Only the code that's actually used is included so the resulting binaries are pretty small for a kernel.
The mechanism used for the compile time selection of concrete module implementations is OCaml functors (not to be confused with Haskell functors). Few other languages have this feature and it leads to an interesting programming style. For example if you want to have a map with keys of your custom type you define a module and say
type t = my_type, add acomparefunction to it and then saymodule MyMap = Map.Make(MyModule), theMyMapmodule will then have all the map functions specialized for your type.1 u/PhantomOfTheTypes 11 Aug 2015 19:18
There was a great talk about this at the Haskell Symposium at ICFP 2014 https://www.youtube.com/watch?v=UEIHfXLMtwA
0 u/SpaceMonkey 11 Aug 2015 11:28
Really interesting