diff --git a/dhall/src/Dhall/Binary.hs b/dhall/src/Dhall/Binary.hs index ddc81bac0c..183961f5ef 100644 --- a/dhall/src/Dhall/Binary.hs +++ b/dhall/src/Dhall/Binary.hs @@ -50,7 +50,7 @@ import Dhall.Syntax , Var(..) ) -import Data.Foldable (toList, foldl') +import Data.Foldable (toList) import Data.Monoid ((<>)) import Data.Text (Text) import Data.Void (Void, absurd) @@ -234,15 +234,19 @@ decodeExpressionInternal decodeEmbed = go case tag of 0 -> do - f <- go + !f <- go - xs <- replicateDecoder (len - 2) go + let loop n !acc + | n <= 0 = return acc + | otherwise = do + !x <- go + loop (n - 1) (App acc x) - if null xs - then die "Non-standard encoding of a function with no arguments" - else return () + let nArgs = len - 2 - return (foldl' App f xs) + if nArgs <= 0 + then die "Non-standard encoding of a function with no arguments" + else loop nArgs f 1 -> do case len of