Zuletzt geändert: Mo, 24.04.2006

«K12/K13» Hyper.hs «PDF», «POD»



Download
{-# OPTIONS_GHC -fglasgow-exts #-}
module Hyper where

import Data.Set (Set)
import qualified Data.Set as Set (empty, singleton, elems, map, union, fold)

class Hyper a b c | a b -> c where
  infixl 6 >>+<<
  infixl 6 >>-<<
  infixl 7 >>*<<

  (>>+<<) :: a -> b -> c
  (>>-<<) :: a -> b -> c
  (>>*<<) :: a -> b -> c

instance (Num a, Ord a) => Hyper (Set a) a (Set a) where
  as >>+<< b = Set.map (+ b) as
  as >>-<< b = Set.map ((-) b) as
  as >>*<< b = Set.map (* b) as

instance (Num a, Ord a) => Hyper a (Set a) (Set a) where
  a >>+<< bs = Set.map (a +) bs
  a >>-<< bs = Set.map (a -) bs
  a >>*<< bs = Set.map (a *) bs

instance (Num a, Ord a) => Hyper (Set a) (Set a) (Set a) where
  as >>+<< bs = Set.fold Set.union Set.empty $ Set.map (>>+<< bs) as
  as >>-<< bs = Set.fold Set.union Set.empty $ Set.map (>>-<< bs) as
  as >>*<< bs = Set.fold Set.union Set.empty $ Set.map (>>*<< bs) as