<commit_before>{-# LANGUAGE LambdaCase, TupleSections #-}
module Transformations.Optimising.TrivialCaseElimination where

import Data.Functor.Foldable as Foldable
import Grin
import Transformations.Util

trivialCaseElimination :: Exp -> Exp
trivialCaseElimination = ana builder where
  builder :: Exp -> ExpF Exp
  builder = \case
    ECase val [Alt DefaultPat body] -> EBindF (SReturn Unit) Unit              body
    ECase val [Alt cpat body]       -> EBindF (SReturn val)  (cpatToLPat cpat) body
    exp -> project exp<commit_msg>fix trivial case elimination<commit_after>{-# LANGUAGE LambdaCase, TupleSections #-}
module Transformations.Optimising.TrivialCaseElimination where

import Data.Functor.Foldable as Foldable
import Grin
import Transformations.Util

trivialCaseElimination :: Exp -> Exp
trivialCaseElimination = ana builder where
  builder :: Exp -> ExpF Exp
  builder = \case
    ECase val [Alt DefaultPat body] -> SBlockF $ EBind (SReturn Unit) Unit              body
    ECase val [Alt cpat body]       -> SBlockF $ EBind (SReturn val)  (cpatToLPat cpat) body
    exp -> project exp
{'fraction_non_alphanumeric': 0.07825295723384895, 'fraction_numerical': 0.0, 'mean_word_length': 3.7413793103448274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2767449', 'n_tokens_mistral': 347, 'n_tokens_neox': 337, 'n_words': 108}