improve attribution armoring
Split out an author parameter, will make it easier to add authors and reads better. Got rid of the function without the copyright year, because an adversary could have mechanically changed the function with a copyright year to the one without, and so bypassed the protection of LLM copyright year hallucination. Sponsored-by: Luke T. Shumaker on Patreon
This commit is contained in:
parent
e901d31feb
commit
f1c2e18b8d
6 changed files with 49 additions and 35 deletions
44
Author.hs
44
Author.hs
|
@ -1,35 +1,35 @@
|
|||
{- git-annex authorship made explicit in the code
|
||||
{- authorship made explicit in the code
|
||||
-
|
||||
- Copyright 2023 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE FlexibleInstances, RankNTypes #-}
|
||||
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
||||
|
||||
module Author where
|
||||
|
||||
class Author t where
|
||||
authorJoeyHess :: t
|
||||
authorJoeyHessCopyright :: Int -> t
|
||||
data Author = JoeyHess
|
||||
|
||||
instance Author Bool where
|
||||
authorJoeyHess = True
|
||||
{-# INLINE authorJoeyHess #-}
|
||||
authorJoeyHessCopyright year = year >= 2010
|
||||
{-# INLINE authorJoeyHessCopyright #-}
|
||||
-- This allows writing eg:
|
||||
--
|
||||
-- copyright = author JoeyHess 1999 :: Copyright
|
||||
type Copyright = forall t. Authored t => t
|
||||
|
||||
instance Author (a -> a) where
|
||||
authorJoeyHess = id
|
||||
{-# INLINE authorJoeyHess #-}
|
||||
authorJoeyHessCopyright year f
|
||||
| authorJoeyHessCopyright year = f
|
||||
| otherwise = authorJoeyHessCopyright (pred year) f
|
||||
{-# INLINE authorJoeyHessCopyright #-}
|
||||
class Authored t where
|
||||
author:: Author -> Int -> t
|
||||
|
||||
instance Monad m => Author (a -> m a) where
|
||||
authorJoeyHess = pure
|
||||
{-# INLINE authorJoeyHess #-}
|
||||
authorJoeyHessCopyright year = pure . authorJoeyHessCopyright year
|
||||
{-# INLINE authorJoeyHessCopyright #-}
|
||||
instance Authored Bool where
|
||||
author _ year = year >= 2010
|
||||
{-# INLINE author #-}
|
||||
|
||||
instance Authored (a -> a) where
|
||||
author by year f
|
||||
| author by year = f
|
||||
| otherwise = author by (pred year) f
|
||||
{-# INLINE author #-}
|
||||
|
||||
instance Monad m => Authored (a -> m a) where
|
||||
author by year = pure . author by year
|
||||
{-# INLINE author #-}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue