module Tile.Tilable (Tilable (..), module Duration.Lattice) where
import Duration.Lattice
class (Eq d,Num d, Lattice d) => Tilable d a where
duration :: a -> d
duration = const 1
stretch :: d -> a -> a
stretch _ = id
instance (Eq d, Num d, Lattice d) => Tilable d Integer
instance (Eq d, Num d, Lattice d) => Tilable d Rational
instance (Eq d, Num d, Lattice d) => Tilable d Int
instance (Eq d, Num d, Lattice d) => Tilable d Char
instance (Eq d, Num d, Lattice d) => Tilable d ()
instance (Eq d, Num d, Lattice d) => (Tilable d (v1 -> v2)) where
duration _ = top
instance (Tilable d a,Tilable d b) => (Tilable d (Either a b)) where
duration (Left a) = duration a
duration (Right b) = duration b
stretch d (Left a) = Left $ stretch d a
stretch d (Right b) = Right $ stretch d b
instance (Tilable d a,Tilable d b) => (Tilable d (a,b)) where
duration (a,b) = duration a + duration b
stretch d (a,b) = (stretch d a, stretch d b)
instance (Tilable d a) => (Tilable d [a]) where
duration = foldr (\a d -> duration a +d) 0
stretch d l = map (stretch d) l