[Haskell-cafe] Type without a data constructor?
Dan Weston
westondan at imageworks.com
Mon Aug 6 19:51:39 EDT 2007
The answer would be phantom types, but your example doesn't use them.
Each of your types has at least one constructor:
Possibly you overlooked the infix constructor :||: ?
Tree a has 2 constructors: Tip and Node
SearchCondition has 2 constructors: Term and (:||:)
Term a has 1 constructor : Constant
*Prelude> :t Tip
Tip :: Tree a
*Prelude> :t Node
Node :: a -> Tree a -> Tree a -> Tree a
*Prelude> :t Term True
Term True :: SearchCondition
*Prelude> :t (:||:)
(:||:) :: SearchCondition -> Term Bool -> SearchCondition
*Prelude> :t Constant True
Constant True :: Term Bool
Dan Weston
Rahul Kapoor wrote:
> Most examples for defining algebraic types include data constructors like so:
>
> data Tree a = Tip | Node a (Tree a) (Tree a)
>
> I by mistake defined a type which did not specify a data constructor :
>
> data SearchCondition = Term Bool | SearchCondition :||: (Term Bool)
> data Term a = Constant a
>
> sc :: SearchCondition
> sc = Term True
>
> is ok, but
>
> sc :: SearchCondition
> sc = Constant True
>
> is not (though this is what I intended to capture!).
>
> So the question is what are types with no constructors good for? A
> simple example would be appreciated.
>
> Rahul
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
More information about the Haskell-Cafe
mailing list