DEV Community

loading...

Discussion on: Improving Elm's compiler output

robinheghan profile image
Robin Heggelund Hansen Author

This talks about Inline Caching => inline caches is something else, inlining is just replacing a function call with the implementation of the function.

without Inline Caching code of inlined foldl's loop is specilized for argument functions type => without inlining, the foldl's loop cannot be specialized because it has to handle all possible argument types.

Thread Thread
mshaka profile image
m-shaka

Thank you! You mean monomophishing is to specialize code by inlining function call, right? If so, I can't understand what without actually having a monomorphishing compiler means...

Thread Thread
robinheghan profile image
Robin Heggelund Hansen Author

monomorphising doesn't do inling. When a monomorphising compiler sees the following code:

listmap : (a -> b) -> List a -> List b
listmap fn list =
    List.foldl (\a acc -> fn a :: acc) list
    |> List.reverse

strs = listmap String.fromInt [ 1, 2, 3 ]

strs = listmap isEven [ 1, 2, 3 ]
Enter fullscreen mode Exit fullscreen mode

it will generate two versions of listmap, one which has the type (Int -> String) -> List Int -> List String and one which has the type (Int -> Bool) -> List Int -> List Bool. It will then use the specialized listmap implementations where it can.

This allows the compiler to specialize code better, because it has precise type information.

Thread Thread
mshaka profile image
m-shaka

Oh...I misread that you used "monomorphishing" like as this article explained.

I've published my translation! zenn.dev/mshaka/articles/633027bef...

I appreciate your patience and kindness!