You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typecheck the following example (this is a slightly adjusted example from a question on discord):
module Printf
import Data.String
%defaulttotaldataFormat=FIntFormat-- %d|FStringFormat-- %s|FOtherCharFormat|FEndformat:List Char -> Format
format Nil=FEnd
format ('%'::'d':: xs) =FInt (format xs)
format ('%'::'s':: xs) =FString (format xs)
format (x :: xs) =FOther x (format xs)
0InterpFormat: Format ->TypeInterpFormat (FInt f) =Int->InterpFormat f
InterpFormat (FString f) =String->InterpFormat f
InterpFormat (FOther_ f) =InterpFormat f
InterpFormatFEnd=StringformatString: String -> Format
formatString s = format (unpack s)
toFunction: (fmt : Format) -> String -> InterpFormat fmt
toFunction (FInt x) str =\y => toFunction x (str ++show y)
toFunction (FString x) str =\y => toFunction x (str ++ y)
toFunction (FOther c x) str = toFunction x (str ++ singleton c)
toFunction FEnd str = str
printf: (s : String) -> InterpFormat (formatString s)
printf s = toFunction (formatString s) ""message: String
message = printf "My name is %s and I am %d years old"
Expected Behavior
Fails with a type error after a short time.
Observed Behavior
Consumes all my system's memory and dies after a couple of minutes.
The reason seems to be the implementation of unpack: For shorter messages, it produces a very large syntax tree (at least quadratic w.r.t. to the length of the string). It was pretty straight forward to come up with a different implementation of unpack that performs much better at compile time. I'll submit a PR in a moment.
The text was updated successfully, but these errors were encountered:
Steps to Reproduce
Typecheck the following example (this is a slightly adjusted example from a question on discord):
Expected Behavior
Fails with a type error after a short time.
Observed Behavior
Consumes all my system's memory and dies after a couple of minutes.
The reason seems to be the implementation of
unpack
: For shortermessage
s, it produces a very large syntax tree (at least quadratic w.r.t. to the length of the string). It was pretty straight forward to come up with a different implementation ofunpack
that performs much better at compile time. I'll submit a PR in a moment.The text was updated successfully, but these errors were encountered: