I'm sorry there is something that I can't understand in Inlining section.
Is the intermediary number value is accumlator?
What does we were folding over other things mean actually? And why aren't ints stored? In my knowledge, all local variables are stored on the stack or the heap.
other things like Booleans, Maps, Sets, Floats or other Objects. «If we weren’t storing ints» refers to the option of storing other intermediate values like objects.
I'm so sorry I have one more question, but this is last one.
It's about this sentence.
This is like getting the benefits of a monomorphising compiler, without actually having a monomorphishing compiler.
What I understand is below:
This talks about Inline Caching. If foldl is inlined, the function as argument of foldl is also inlined, so without Inline Caching code of inlined foldl's loop is specilized for argument functions type.
Is this right?
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.
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...
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 ]
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.
Interesting article! Can I translate it into Japanese?
Sure :)
I'm sorry there is something that I can't understand in
Inlining
section.the intermediary number value
is accumlator?we were folding over other things
mean actually? And why aren't ints stored? In my knowledge, all local variables are stored on the stack or the heap.I'm looking forward to your answer
Thanks for your quick response! I understood.
I'm so sorry I have one more question, but this is last one.
It's about this sentence.
What I understand is below:
This talks about Inline Caching. If
foldl
is inlined, the function as argument offoldl
is also inlined, so without Inline Caching code of inlinedfoldl
's loop is specilized for argument functions type.Is this right?
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.Thank you! You mean
monomophishing
is to specialize code by inlining function call, right? If so, I can't understand whatwithout actually having a monomorphishing compiler
means...monomorphising doesn't do inling. When a monomorphising compiler sees the following code:
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 specializedlistmap
implementations where it can.This allows the compiler to specialize code better, because it has precise type information.
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!