<commit_before>{-# LANGUAGE PatternGuards, ViewPatterns #-}

module Hint.Util where

import HSE.All


-- generate a lambda, but prettier (if possible)
niceLambda :: [String] -> Exp_ -> Exp_
niceLambda xs (Paren _ x) = niceLambda xs x
niceLambda xs (Lambda _ ((view -> PVar_ v):vs) x) = niceLambda (xs++[v]) (Lambda an vs x)
niceLambda xs (Lambda _ [] x) = niceLambda xs x
niceLambda [x] (App _ a (view -> Var_ b)) | x == b = a
niceLambda [x] (App _ a (Paren _ (App _ b (view -> Var_ c))))
    | isAtom a && isAtom b && x == c
    = if a ~= "$" then LeftSection an b (toNamed "$") else InfixApp an a (toNamed ".") b
niceLambda [x] (InfixApp _ a op b)
    | view a == Var_ x = RightSection an op b
    | view b == Var_ x = LeftSection an a op
niceLambda [x,y] (view -> App2 op (view -> Var_ x1) (view -> Var_ y1))
    | x1 == x && y1 == y = op
    | x1 == y && y1 == x = App an (toNamed "flip") op
niceLambda ps x = Lambda an (map toNamed ps) x<commit_msg>Add an extra rule to niceLambda<commit_after>{-# LANGUAGE PatternGuards, ViewPatterns #-}

module Hint.Util where

import HSE.All


-- generate a lambda, but prettier (if possible)
niceLambda :: [String] -> Exp_ -> Exp_
niceLambda xs (Paren _ x) = niceLambda xs x
niceLambda xs (Lambda _ ((view -> PVar_ v):vs) x) = niceLambda (xs++[v]) (Lambda an vs x)
niceLambda xs (Lambda _ [] x) = niceLambda xs x
niceLambda [x] (App _ a (view -> Var_ b)) | x == b = a
niceLambda [x] (App _ a (Paren _ (App _ b (view -> Var_ c))))
    | isAtom a && isAtom b && x == c
    = if a ~= "$" then LeftSection an b (toNamed "$") else InfixApp an a (toNamed ".") b
niceLambda [x] (InfixApp _ a op b)
    | view a == Var_ x = RightSection an op b
    | view b == Var_ x = LeftSection an a op
niceLambda [x,y] (view -> App2 op (view -> Var_ x1) (view -> Var_ y1))
    | x1 == x && y1 == y = op
    | x1 == y && y1 == x = App an (toNamed "flip") op
niceLambda [] x = x
niceLambda ps x = Lambda an (map toNamed ps) x
{'fraction_non_alphanumeric': 0.15364850976361769, 'fraction_numerical': 0.007194244604316547, 'mean_word_length': 3.031055900621118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7439609', 'n_tokens_mistral': 732, 'n_tokens_neox': 719, 'n_words': 291}