Why do I need to be explicit about binary

Robert Virding robert.virding@REDACTED
Tue Jan 13 22:21:33 CET 2004


----- Original Message ----- 
From: "Zeke Bachholz" <zeke_bachholz@REDACTED>
To: <erlang-questions@REDACTED>
Sent: Monday, January 12, 2004 2:59 PM
Subject: Why do I need to be explicit about binary


> Hi,
> 
> Can anyone explain why 11> does not work but 12> does?
> A is assigned a binary value, so why do I need to be explicit about it.
> 
> 10> A = <<2:8>>.
> <<2>>
> 11> B = <<1:8, A, 3:8>>.
> ** exited: {badarg,[{erl_eval,expr,3}]} **
> 12> B = <<1:8, A/binary, 3:8>>.
> <<1,2,3>>

The default type of an element in a binary is integer, so you have to explicitly tell it when something is not an integer, e.g. when it is a binary. It is the same with floats. It is a Good Thing to be explicit here seeing some of the qualifiers have different constraints for different type, e.g. the size a float must be 32 or 64. If the type was implicit you could easily be burned.

Robert




More information about the erlang-questions mailing list