type safety (was Re: FAQ terminology harmonisation)
Peter-Henry Mander
erlang@REDACTED
Fri Apr 4 19:12:23 CEST 2003
I was thinking of something like this (not compiled or tested, sorry)
which I find kinda useful sometimes.
fn(#a_record{field=an_atom}) ->
%% do stuff specific to a record with field=an_atom...
fn(Record=#a_record{field=Field}) ->
%% do stuff for other values of field...
fn(Anything) ->
%% do anything... Probably shouldn't!
But I have a feeling we may be thinking of different purposes. Sorry I
can't elaborate right now, I've gotta scoot, family needs me.
Pete.
Chris Pressey wrote:
> On Fri, 04 Apr 2003 08:03:49 +0100
> Peter-Henry Mander <erlang@REDACTED> wrote:
>
>
>>Hmm... This emphasis on exact matching on type would potentially break
>>
>>an aspect of Erlang I have learnt to appreciate: pattern matching. I
>>can make a function match exactly or match with increasing degrees of
>>generality. A special case function first, followed by general case.
>>If none match, an exception occurs. I can work with a bit of dicipline
>>and tag my tuples, and enforce that functions only acccept tagged
>>tuples.
>>
>>Pete.
>
>
> Do you mean you write functions like this?
>
> case Value of
> Tuple when is_tuple(Tuple) ->
> case Tuple of
> Record when is_record(Record, my_record) ->
> do_stuff(Record)
> end
> end
>
> That seems silly. You probably mean like this:
>
> case Value of
> Record when is_record(Record, my_record) ->
> do_stuff(Record);
> Tuple when is_tuple(Tuple) ->
> do_other_stuff(Tuple)
> end
>
> But if records were opaque, that sort of match wouldn't break, either.
>
> -Chris
>
>
>
More information about the erlang-questions
mailing list