# HG changeset patch # User Yasutaka Higa # Date 1409969014 -32400 # Node ID 88d6897c391a8e8c432b579905fc9cad85c0104c # Parent 158ae705cd16c7507d3ce0c673e6b7cbd6f64e0f Redefine Similar. reject function in data diff -r 158ae705cd16 -r 88d6897c391a similar.hs --- a/similar.hs Tue Sep 02 16:59:52 2014 +0900 +++ b/similar.hs Sat Sep 06 11:03:34 2014 +0900 @@ -1,31 +1,21 @@ -{-# LANGUAGE GADTs #-} +data Similar a = Single a | Similar a (Similar a) -data Similar a = (Eq a) => Similar a (a -> a) a +same :: (Eq a) => Similar a -> a +same (Single x) = x +same (Similar x s) = if x == (same s) then x else undefined instance (Eq a) => Eq (Similar a) where - s == ss = same s == same ss + s == ss = (same s) == (same ss) -same :: (Eq a) => Similar a -> a -same (Similar x f y) = if (f x) == y then y else undefined +instance Functor Similar where + fmap f (Single a) = Single (f a) + fmap f (Similar a s) = Similar (f a) (fmap f s) + +{- mu :: (Eq a) => Similar (Similar a) -> Similar a mu (Similar a f b) = if ((f a) == b) then b else undefined -class EqFunctor f where - eqmap :: (Eq a, Eq b) => (a -> b) -> f a -> f b - -instance EqFunctor Similar where - eqmap f s = Similar fs id fs - where fs = f \$ same s - -class EqMonad m where - (>>=) :: (Eq a, Eq b) => m a -> (a -> m b) -> m b - return ::(Eq a) => a -> m a - -instance EqMonad Similar where - return x = Similar x id x - s >>= f = mu (eqmap f s) - similar :: (Eq a) => (a -> a) -> (a -> a) -> a -> a similar f g x = same \$ Similar x g (f x) @@ -53,3 +43,4 @@ *** Exception: Prelude.undefined -} +-}