[erlang-questions] Using different number types

Bengt Kleberg <>
Mon May 28 08:52:40 CEST 2007


On 2007-05-28 01:10, Jay Anderson wrote:
...deleted
> An idea I've thought of is to define a 'numeric operations' module which
> represents these operations and knows how to delegate to the appropriate module.
> There's still the problem of numeric coercion which I was thinking of solving
> this in a way similar to ruby's coerce method. The problem with this is that
> whenever a new type is created this 'numeric operations' module has to be
> updated also.

to avoid changing the 'numeric operations' module you could make each 
number a tuple/record and have the appropriate module in the record.

-record( numeric_operation, {module, value}).

-module(numeric_operation).

-export([add/2]).

add( #numeric_operation(module=Module, value=Value1}, 
#numeric_operation(module=Module, value=Value2} ) ->
	Module:add( Value12, Value2 ).


bengt
-- 
Those were the days...
    EPO guidelines 1978: "If the contribution to the known art resides
    solely in a computer program then the subject matter is not
    patentable in whatever manner it may be presented in the claims."



More information about the erlang-questions mailing list