Version française
Home     About     Download     Resources     Contact us    
Browse thread
empty type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bruno De Fraine <Bruno.De.Fraine@v...>
Subject: Re: RE : [Caml-list] empty type
On 19 Feb 2007, at 17:03, Andrej Bauer wrote:

> Mathias Kende wrote:
>> It's not a type, but just a valid name for a constructor that can be
>> redefined if necessary (although one surely does not want to do so).
>
> Way cool:
>
> # type t = () of int * int ;;
> type t = () of int * int
> # () (3, 4) ;;
> - : t = () (3, 4)

If you redefine :: you get an infix constructor:

# type expr = Num of int | :: of expr * expr ;;
type expr = Num of int | :: of expr * expr
# Num 1 :: Num 2 :: Num 3 ;;
- : expr = :: (Num 1, :: (Num 2, Num 3))
# :: (Num 2, Num 3) ;;
Syntax error
# let a :: b = Num 1 :: Num 2 :: Num 3 ;;
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
Num _
val a : expr = Num 1
val b : expr = :: (Num 2, Num 3)

Bruno

-- 
Bruno De Fraine
Vrije Universiteit Brussel
Faculty of Applied Sciences, INFO - SSEL
Room 4K208, Pleinlaan 2, B-1050 Brussels
tel: +32 (0)2 629 29 75
fax: +32 (0)2 629 28 70
e-mail: Bruno.De.Fraine@vub.ac.be