I am confused about the difference between pack and fastPack functions in Idris2 (as of 0.7.0). Both have the same signature:
:t pack
Prelude.pack : List Char -> String
:t fastPack
Prelude.fastPack : List Char -> String
pack works as advertised and converts a list of Chars into a String.
pack ['a'] ++ pack ['b']
renders:
"ab"
But I can't seem to get Strings out of fastPack.
fastPack ['a'] ++ fastPack ['b']
renders:
prim__strAppend (fastPack ['a']) (fastPack ['b'])
I am not sure whether some laziness is going on here. But some of the base code I am testing uses fastPack, so the result expression becomes large very quickly.
Is there a way to get the normal string value out of these fastPack expressions?
(In this example, "ab" from prim__strAppend (fastPack ['a']) (fastPack ['b']). I tried show and force, to no avail.)
packis implemented in Idris:fastPpackis a foreign function:The ECMAScript implementation just uses
Array.prototype.join.The Scheme implementation looks like this in the Chez backend:
And in the Gambit backend:
And in the Racket backend:
For the C backend, it is implemented like this:
That requires far more intimacy with Idris's FFI than I possess.
Interestingly, there is a
%transformdefined which will automatically replacepackwithfastPack: