[erlang-questions] Checking Types at Runtime

Tristan Sloughter tristan.sloughter@REDACTED
Wed Jul 13 02:35:24 CEST 2011


OK, that is what I thought. But declaring specs and relying on dialyzer for
problems doesn't help when I want to match on a type. But I guess I'll have
to either bundle the "type" with the value of the record field. Or have some
module that accepts a record field atom and returns its "type"...

Tristan

On Tue, Jul 12, 2011 at 7:31 PM, Eric Merritt <ericbmerritt@REDACTED>wrote:

> Thats not possible at the moment. Dialyzer will do a good job at
> compile time warning you that something is wrong. I think thats about
> your best bet.
>
> Now, as I understand it this type information *is* retained in the
> compiled beam file. So you could possibly write something that will
> check the types for you, but I don't think it would be very
> performant.
>
> I think the right answer, at least with out more details, is to do a
> good job declaring specs and using them, while relying on dialyzer to
> tell you when there are problems.
>
> On Tue, Jul 12, 2011 at 6:26 PM, Tristan Sloughter
> <tristan.sloughter@REDACTED> wrote:
> > I'm pretty sure this isn't possible but I wanted to be sure before
> working
> > around the lack of it.
> > if I have a type and record like:
> > -type password() :: binary().
> > -record(user, {username :: binary(),
> >                     password  :: password()}.
> > At run time there is no way to tell a field is suppose to be of some type
> > during runtime, right?
> > Basically I'd like to be able to have generic or generated create
> functions
> > for records that may have to modify arguments (like a password has to be
> > encrypted from the string provided) when creating the record. So the
> create
> > function would pass each field, its value and its type to a transform
> > function that matches on type and returns the appropriately modified
> value.
> > Any ideas on how to do this with type definitions or do I need to use
> tuples
> > and an atom like {Type, Value} for the value of every field to achieve
> this?
> > Thanks,
> > Tristan
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110712/0ebe7ded/attachment.htm>


More information about the erlang-questions mailing list