<commit_before>{-# LANGUAGE DeriveDataTypeable #-}

module Propellor.Types.Info (
	Info,
	IsInfo(..),
	addInfo,
	getInfo,
	propigatableInfo,
	InfoVal(..),
	fromInfoVal,
	Typeable,
) where

import Data.Dynamic
import Data.Monoid
import Data.Maybe

-- | Information about a Host, which can be provided by its properties.
--
-- Any value in the `IsInfo` type class can be added to an Info.
data Info = Info [(Dynamic, Bool)]

instance Show Info where
	show (Info l) = "Info " ++ show (length l)

instance Monoid Info where
 	mempty = Info []
	mappend (Info a) (Info b) = Info (a <> b)

-- | Values stored in Info must be members of this class.
--
-- This is used to avoid accidentially using other data types
-- as info, especially type aliases which coud easily lead to bugs.
-- We want a little bit of dynamic types here, but not too far..
class (Typeable v, Monoid v) => IsInfo v where
	-- | Should info of this type be propigated out of a
	-- container to its Host?
	propigateInfo :: v -> Bool<commit_msg>better Show for Info<commit_after>{-# LANGUAGE DeriveDataTypeable #-}

module Propellor.Types.Info (
	Info,
	IsInfo(..),
	addInfo,
	getInfo,
	propigatableInfo,
	InfoVal(..),
	fromInfoVal,
	Typeable,
) where

import Data.Dynamic
import Data.Monoid
import Data.Maybe

-- | Information about a Host, which can be provided by its properties.
--
-- Any value in the `IsInfo` type class can be added to an Info.
data Info = Info [(Dynamic, Bool)]

instance Show Info where
	show (Info l) = "Info " ++ show (map (dynTypeRep . fst) l)

instance Monoid Info where
 	mempty = Info []
	mappend (Info a) (Info b) = Info (a <> b)

-- | Values stored in Info must be members of this class.
--
-- This is used to avoid accidentially using other data types
-- as info, especially type aliases which coud easily lead to bugs.
-- We want a little bit of dynamic types here, but not too far..
class (Typeable v, Monoid v) => IsInfo v where
	-- | Should info of this type be propigated out of a
	-- container to its Host?
	propigateInfo :: v -> Bool
{'fraction_non_alphanumeric': 0.10270270270270271, 'fraction_numerical': 0.0, 'mean_word_length': 3.3879310344827585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4794639', 'n_tokens_mistral': 655, 'n_tokens_neox': 643, 'n_words': 290}