Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] polymorphic type constructor deconstructor
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] polymorphic type constructor deconstructor
Dnia sob 7. czerwca 2003 00:37, Jeffrey J. Cook napisa³:

> I would like to simplify this into a function taking a type constructor
> of type 'reply' and a type constructed value of type 'reply' and return
> the contents of the type constructed value, such as (int * int) from
> Foo of int * int. This function would internally have a match statement
> and throw an exception if its not of the right type constructor.

I see no other way than writing these functions manually. Just write them once 
and use them instead of passing constructors.

BTW, the contents of 'REPLY_do_that of successlevel * int' is two things 
separately, not a pair. You can't match against 'Reply_do_that p'. Similarly
for construction.

> The only solution, using this approach, that I can think of, is by passing
> a dummy constructed value, and pattern matching it against the real
> constructed value, throwing an exception if it isn't of the right
> constructor, otherwise decontructing the value and returning the data
> within.

There is no need for dummy values. Just write a matching function for each 
constructor manually. It's not that painful and there is no good other way 

> So, is there any way to polymorphically deconstruct a type constructed
> value, which is type safe by providing either a dummy constructed value or
> a dummy constructor?

What type would such a deconstructor have?

   __("<         Marcin Kowalczyk

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: