common type synonyms (haskell) 
Author Message
 common type synonyms (haskell)

Hi all.

I sometimes find myself declare type synonyms like :

type Transf a = a -> a
type Comb a   = a -> a -> a

type Pred a     = a -> Bool
type BiPred a b = a -> b -> Bool --hmm

type Rel a = BiPred a a
type Cmp a = a -> a -> Ordering

type Cont o a = (a -> o) -> o
--(is this correct name ? (isn't a -> o the continuation ?))

--s -> (a,s) ?
--(a,s) -> (b,s) ?

and then use these in various functions
(only where the intended meaning fits/is intuitive/appropriate, of course)
like :    (yes i looked through List.hs,Prelude.hs :)

(warning : too long list of examples (possibly worng somewhere))

sort          :: Ord a => Transf [a]
sortBy        :: Cmp a -> Transf [a]
insert        :: Ord a => a -> Transf [a]
insertBy      :: Cmp a -> a -> Transf [a]
delete        :: Eq  a => a -> Transf [a]
deleteBy      :: Rel a -> a -> Transf [a]
nub           :: Eq  a => Transf [a]
nubBy         :: Rel a -> Transf [a]
(\\)          :: Eq  a => Comb [a]
deleteFirstBy :: Rel a -> Comb [a]
union         :: Eq  a => Comb [a]
unionBy       :: Rel a -> Comb [a]
intersect     :: Eq  a => Comb [a]
intersectBy   :: Rel a -> Comb [a]

isPrefixOf  :: Eq a => Rel [a]
isSuffixOf  :: Eq a => Rel [a]
transpose   :: Transf [[a]]
intersperse :: a -> Transf [a]
tail        :: Transf [a]
take        :: Int -> Transf [a]
drop        :: Int -> Transf [a]
takeWhile   :: Pred a -> Transf a
dropWhile   :: Pred a -> Transf a
init        :: Transf [a]
tail        :: Transf [a]
reverse     :: Transf [a]
cycle       :: Transf [a]
elem        :: Eq a => a -> Pred [a]
notElem     :: Eq a => a -> Pred [a]
--elemBy ??
all         :: Pred a -> Pred [a]
any         :: Pred a -> Pred [a]

min       :: Ord a => Comb a
max       :: Ord a => Comb a
minimum   :: Ord a => [a] -> a
minimumBy :: Comb a -> [a] -> a
maximum   :: Ord a => [a] -> a
maximumBy :: Comb a -> [a] -> a

iterate     :: Transf a -> a -> [a]
twice       :: Transf (Transf a)
selfcompose :: Int -> Transf (Transf a)

foldr1  :: Comb a -> [a] -> a
foldl1  :: Comb a -> [a] -> a
scanr1  :: Comb a -> Transf [a]
scanl1  :: Comb a -> Transf [a]
filter  :: Pred a -> Transf [a]
null    :: Pred [a]

not :: Transf Bool

isDigit    :: Pred Char
...
protectEsc :: Pred Char -> Transf ([Char] -> a)

asTypeOf :: Comb a
until    :: Pred a -> Transf (Transf a)
seq      :: a -> Transf b

(==)      :: Eq a => Rel a
(<=)      :: Ord a => Rel a
compare   :: Ord a => Cmp a
(+)       :: Num a => Comb a
even      :: Integral a => Pred a
odd       :: Integral a => Pred a
succ      :: Enum a => Transf a
pred      :: Enum a => Transf a
(>>)      :: Monad m => m a -> Transf (m b)
interact  :: Transf String -> IO ()
readParen :: Bool -> Transf (ReadS a)
showParen :: Bool -> Transf ShowS
(++)      :: Comb [a]
(||)      :: Comb Bool
(&&)      :: Comb Bool
negate    :: Num a => Transf a
(:)       :: a -> Transf [a]

modifyLeftSubTree  :: Transf (Transf (Tree a))  -- ;-)
modifyRightSubTree :: Transf (Transf (Tree a))  --
rotateLeft  :: Transf (Tree a)
rotateRight :: Transf (Tree a)
rotateSubLeftThenRight :: Transf (Tree a)
rotateSubRightThenLeft :: Transf (Tree a)
mirrorTree :: Transf (Tree a)
mergeTree  :: Comb (Tree a)

liftToSet    :: Transf [a] -> Transf (Set a) --list implementation of Set
lowerFromSet :: Transf (Set a) -> Transf [a]
--with data/newtype Set a = MkSet {unSet [a]}

(&&&) :: Comb (Pred a)
(|||) :: Comb (Pred a)

iterateUntil :: Pred a -> Transf (Transf a)  --heh

putchar :: Char -> Transf ([Response] -> [Request])
getchar :: Cont ([Response] -> [Request]) Char

(>>=) :: Monad m => m a -> Cont (m b) a

(Cont could be used with functions taking explicit continuations ..
 (would
    type Cont a = forall o . (a -> o) -> o
  be better ? (oops, cant use forall in type synonyms (?))
  (type Map f = forall a b . (a -> b) -> (f a -> f b) :)
 )
)

so there is plenty of examples where these could be appropriate (?)
but of course one can use them to much ..

so the question is :
do you think there is a /use for/place for using/ suchlike type synonyms ?
(ShowS,ReadS is used ..)

(i think they sometimes make it easier to reason with
higher-order-functions)

and if so, shouldn't they be in some standard library ?
(Synonym.hs ?)

(so there isn't incompatible names for the same thing around ..)

Ok.

(sorry for this long post)

--
Stefan Lj
md9slj

The infinity that can be finitly expressed is not the true infinity



Sun, 07 Sep 2003 22:22:41 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. type synonyms

2. Lowest common denominator function for haskell?

3. Haskell: How do you find most common letter

4. Cycles in Haskell Type Declarations?

5. Haskell - Question about multi-parameter type classes

6. Haskell: type inference is not smart enough?

7. Haskell type system battles

8. what is a qualified type in haskell?

9. Haskell type classes, adding extra constraints

10. Haskell: type conversion? (newbie question)

11. type classes in Haskell

12. Recursive types in Haskell

 

 
Powered by phpBB® Forum Software