<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  Bound.Var
-- Copyright   :  (C) 2012 <NAME>
-- License     :  BSD-style (see the file LICENSE)
--
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  experimental
-- Portability :  portable
--
----------------------------------------------------------------------------
module Bound.Var (Var(..)) where

import Data.Foldable
import Data.Traversable
import Data.Monoid (mempty)
import Data.Bifunctor
import Data.Bifoldable
import Data.Bitraversable
import Control.Applicative
import Control.Monad (ap)
import Prelude.Extras
import Text.Read

-- | "I am not a number, I am a /free monad/!"
--
-- @Var b a@ represents variables that may either be "bound" (@B@) or "free" (@F@)
data Var b a
  = B b -- this is a bound variable
  | F a -- this is a free variable
  deriving (Eq,Ord,Show,Read)

instance Functor (Var b) where
  fmap _ (B b) = B b
  fmap f (F a) = F (f a)

instance Foldable (Var b) where
  foldMap f (F a) = f a
  foldMap _ _ = mempty

instance Traversable (Var b) where
  traverse f (F a) = F <$> f a
  traverse _ (B b) = pure (B b)

instance Applicative (Var b) where
  pure = F
  (<*>) = ap

instance Monad (Var b) where
  return = F
  F a  >>= f = f a
  B b >>= _ = B b

instance Bifunctor Var where
  bimap f _ (B b) = B (f b)
  bimap _ g (F a) = F (g a)

instance Bifoldable Var where
  bifoldMap f _ (B b) = f b
  bifoldMap _ g (F a) = g a

instance Bitraversable Var where
  bitraverse f _ (B b) = B <$> f b
  bitraverse _ g (F a) = F <$> g a

instance Eq2 Var   where (==##)     = (==)
instance Ord2 Var  where compare2   = compare
instance Show2 Var where showsPrec2 = showsPrec
instance Read2 Var where readPrec2  = readPrec

instance Eq b   => Eq1   (Var b) where (==#)      = (==)
instance Ord b  => Ord1  (Var b) where compare1   = compare
instance Show b => Show1 (Var b) where showsPrec1 = showsPrec
instance Read b => Read1 (Var b) where readPrec1  = readPrec
<commit_msg>haddock fix<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  Bound.Var
-- Copyright   :  (C) 2012 <NAME>
-- License     :  BSD-style (see the file LICENSE)
--
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  experimental
-- Portability :  portable
--
----------------------------------------------------------------------------
module Bound.Var (Var(..)) where

import Data.Foldable
import Data.Traversable
import Data.Monoid (mempty)
import Data.Bifunctor
import Data.Bifoldable
import Data.Bitraversable
import Control.Applicative
import Control.Monad (ap)
import Prelude.Extras
import Text.Read

-- | \"I am not a number, I am a /free monad/!\"
--
-- @Var b a@ represents variables that may either be "bound" (@B@) or "free" (@F@)
data Var b a
  = B b -- this is a bound variable
  | F a -- this is a free variable
  deriving (Eq,Ord,Show,Read)

instance Functor (Var b) where
  fmap _ (B b) = B b
  fmap f (F a) = F (f a)

instance Foldable (Var b) where
  foldMap f (F a) = f a
  foldMap _ _ = mempty

instance Traversable (Var b) where
  traverse f (F a) = F <$> f a
  traverse _ (B b) = pure (B b)

instance Applicative (Var b) where
  pure = F
  (<*>) = ap

instance Monad (Var b) where
  return = F
  F a  >>= f = f a
  B b >>= _ = B b

instance Bifunctor Var where
  bimap f _ (B b) = B (f b)
  bimap _ g (F a) = F (g a)

instance Bifoldable Var where
  bifoldMap f _ (B b) = f b
  bifoldMap _ g (F a) = g a

instance Bitraversable Var where
  bitraverse f _ (B b) = B <$> f b
  bitraverse _ g (F a) = F <$> g a

instance Eq2 Var   where (==##)     = (==)
instance Ord2 Var  where compare2   = compare
instance Show2 Var where showsPrec2 = showsPrec
instance Read2 Var where readPrec2  = readPrec

instance Eq b   => Eq1   (Var b) where (==#)      = (==)
instance Ord b  => Ord1  (Var b) where compare1   = compare
instance Show b => Show1 (Var b) where showsPrec1 = showsPrec
instance Read b => Read1 (Var b) where readPrec1  = readPrec

{'fraction_non_alphanumeric': 0.18591968269707487, 'fraction_numerical': 0.008924144769459593, 'mean_word_length': 2.142523364485981, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, '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': '2698400', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1386, 'n_words': 541}