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
Is this interface a good idea?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-05-21 (00:29)
From: Remi VANICAT <vanicat+egroups@l...>
Subject: Re: "ocaml_beginners"::[] Re: Is this interface a good idea?
Matt Armstrong <matt@l...> writes:

> Okay, I did this without modules because modules just obscure my
> understanding. E.g. I have no idea how you can make your "let concat
> = (^)" so terse -- 

simple : ^ is an operator, ( ^ ) is the equivalent function :

foo ^ bar = ( ^ ) foo bar
(by the way foo + bar = ( + ) foo bar .....)

the function in ocaml are first order so if you have a function (say
foo) and you want the function bar to make the same thing you can

let bar = foo

so in this case it become

let concat = ( ^ )

> or why modules let you get away without a constructor for ('a,'b)
> path.

the answer is because you don't need one.

the declaration

type ('a, 'b) path = string

say that path are implemented as string.

then if you want a (relative, directory) path you only make :

( "../foo" : (relative, directory) path)

> This is what I came up with. Thanks for all the help!
> ======================================================================
> type directory
> type file
> type absolute
> type relative
> type ('a,'b) path = Path of string

the problem here is that as the ('a, 'b) path is not abstract, you
don't have the type safety you have with abstract type (as in mine an
Alan example).
Rémi Vanicat