On 3/21/06, Simon Marlow <[EMAIL PROTECTED]> wrote:
By all means have strict tuples in a library somewhere.  They don't need
to have special syntax.

 I have a module Data.Pair which provides pairs with different strictness properties. Perhaps it can be used as a startingpoint.

Cheers,

/Josef
-----------------------------------------------------------------------------
-- |
-- Module      :  Data.Pair
-- Copyright   :  (c) Josef Svenningsson 2005
-- License     :  BSD-style
--
-- Maintainer  :  [EMAIL PROTECTED]
-- Stability   :  experimental
-- Portability :  portable
--
-- Several pair data types with different strictness properties
--
------------------------------------------------------------------------------
module Data.Pair ( Pair(..),
		   StrictLeft(..),
		   StrictRight(..),
		   StrictPair(..)
		  ) where

-- |A class for pairs. We need this to have a consistent interface for
--  several different pair types with different strictness properties.
--  Minimal complete instances are either @first@, @second@ and @pair@
--  or @casePair@ and @[EMAIL PROTECTED]
class Pair p where
  first    :: p a b -> a
  first p  = casePair (\a _ -> a)
  second   :: p a b -> b
  second p = casePair (\_ b -> b)
  casePair :: (a -> b -> c) -> p a b -> c
  casePair c p = c (first p) (second p)
  pair     :: a -> b -> p a b

propPair p = p == pair (first p) (second p)

data StrictLeft  a b = StrictLeft !a  b
data StrictRight a b = StrictRight a !b
data StrictPair  a b = StrictPair !a !b

instance Pair (,) where
  first  (f,_) = f
  second (_,s) = s
  pair f s = (f,s)

instance Pair StrictLeft where
  first  (StrictLeft f _) = f
  second (StrictLeft _ s) = s
  pair f s = StrictLeft f s

instance Pair StrictRight where
  first  (StrictRight f _) = f
  second (StrictRight _ s) = s
  pair f s = StrictRight f s

instance Pair StrictPair where
  first  (StrictPair f _) = f
  second (StrictPair _ s) = s
  pair f s = StrictPair f s
_______________________________________________
Haskell-prime mailing list
[email protected]
http://haskell.org/mailman/listinfo/haskell-prime

Reply via email to