<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Property where

import Data.String
import Data.Text (Text, intercalate)
import Control.Monad.Writer

-------------------------------------------------------------------------------

newtype Key a = Key { unKey :: Text }

instance IsString (Key a) where
  fromString = Key . fromString

-------------------------------------------------------------------------------

newtype Value = Value { unValue :: Text }

class Val a where
  value :: a -> Value

instance IsString Value where
  fromString = Value . fromString

instance Val Text where
  value = Value

instance (Val a, Val b) => Val (a, b) where
  value (a, b) =
    case (value a, value b) of
      (Value x, Value y) -> Value (x <> " " <> y)

instance (Val a, Val b, Val c) => Val (a, b, c) where
  value (a, b, c) = value (a, (b, c))

instance (Val a, Val b, Val c, Val d) => Val (a, b, c, d) where
  value (a, b, c, d) = value (a, (b, (c, d)))

instance Val a => Val [a] where
  value xs = Value (intercalate ", " (map (unValue . value) xs))
<commit_msg>Added Val instances for Double, Value and Mabye.<commit_after>{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-}
module Property where

import Data.String
import Data.Text (Text, intercalate)
import Control.Monad.Writer

newtype Key a = Key { unKey :: Text }

instance IsString (Key a) where
  fromString = Key . fromString

newtype Value = Value { unValue :: Text }
  deriving (Monoid, IsString)

class Val a where
  value :: a -> Value

instance Val Text where
  value = Value

instance Val Double where
  value = fromString . show

instance Val Value where
  value = id

instance Val a => Val (Maybe a) where
  value Nothing  = "none"
  value (Just a) = value a

instance (Val a, Val b) => Val (a, b) where
  value (a, b) =
    case (value a, value b) of
      (Value x, Value y) -> Value (x <> " " <> y)

instance (Val a, Val b, Val c) => Val (a, b, c) where
  value (a, b, c) = value (a, (b, c))

instance (Val a, Val b, Val c, Val d) => Val (a, b, c, d) where
  value (a, b, c, d) = value (a, (b, (c, d)))

instance Val a => Val [a] where
  value xs = Value (intercalate ", " (map (unValue . value) xs))

{'fraction_non_alphanumeric': 0.19662408759124086, 'fraction_numerical': 0.0, 'mean_word_length': 2.4, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, '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': '7271340', 'n_tokens_mistral': 729, 'n_tokens_neox': 720, 'n_words': 306}