[email protected]
[Top] [All Lists]

[Haskell-cafe] ANNOUNCE: Cardinality-0.1

Subject: [Haskell-cafe] ANNOUNCE: Cardinality-0.1
From: Andrey Sisoyev
Date: Wed, 20 Jan 2010 03:06:07 -0800 PST
Hi everybody!

I developed a new package that you may find handy, when transforming
With this package we now have unified ways to make safe transforms "from a
-> Maybe (to a)" and "from -> Maybe to" between simple containers like [],
Maybe, Identity, Map.

Test set that returns all True:

((sContTransT []) :: Maybe (Maybe Int)) == Just Nothing
((sContTrans  ()) :: Maybe (Maybe Int)) == Just Nothing
((sContTransT [1]) :: (Maybe (Maybe Int))) == Just (Just 1)
((sContTransT [1, 2]) :: (Maybe (Maybe Int))) == Nothing
((sContTransT $ Just "Hello") :: (Maybe (Identity String))) == Just
(Identity "Hello")
((sContTransT ["Hello"]) :: Maybe (Identity String)) == Just (Identity
((sContTransT (EmptySet :: EmptySet String)) :: (Maybe [String])) == Just []
((sContTransT "Hello") :: Maybe (EmptySet Char)) == Nothing
((sContTransT ("key", "elem")) :: Maybe (Map String String)) == Just
(singleton "key" "elem")
((sContTrans [("key1", "elem1"), ("key2", "elem2")]) :: Maybe (Map String
String)) == Just (fromList [("key1", "elem1"), ("key2", "elem2")])
((sContTrans (EmptySet :: EmptySet (String, String))) :: Maybe (Map String
String)) == Just empty
((sContTrans []) :: Maybe ()) == Just ()
((sContTrans (NEL 'H' "i!")) :: Maybe String) == Just "Hi!" --
((sContTrans ()) :: Maybe String) == Just ""
((sContTrans "") :: Maybe (Identity Char)) == Nothing
((sContTrans "Hi!") :: Maybe ()) == Nothing

Package is to be found here: http://hackage.haskell.org/package/Cardinality
It dances around cardinality - a measure of of the number of elements of the
set (container); and cardinality constraint of the container. Cardinality
** (): 0 elements
** Identity a: 1 element
** (Maybe a): 0..1 elements
** [a]: 0..Infinity elements
** Map k e: 0..Infinity elements
** (a,a,a): 3 elements

I also introduced 2 containers (which I found strange not to be in the
** data EmptySet a = EmptySet -- (0 elements)
** data NeverEmptyList a = NEL a [a] -- (1..Infinity elements)

The package provides all sorts of transformation instances between this
types (except for tuples, 3ples, 4ples... I didn't make all transforms fo
them - only "list -> (N)ple" and opposites)

I tried also to deal with transforms like "container a -> a", "a ->
container a" using OverlappingInstances. But failed to approve them -
probably due to the lack of experience with this extension. I found them
introducing too much unwanted complexity into the reasoning about types. It
was the last straw to me, when GHC started to proving me, that unity is not
less general then any type variable "a", and demanding tribute of

Any feedback is appreciated.

Best regards, Andrey.
View this message in context: 
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Haskell-Cafe mailing list
[email protected]

<Prev in Thread] Current Thread [Next in Thread>
  • [Haskell-cafe] ANNOUNCE: Cardinality-0.1, Andrey Sisoyev <=