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"...<div>
<br></div><div>Tristan<br><br><div class="gmail_quote">On Tue, Jul 12, 2011 at 7:31 PM, Eric Merritt <span dir="ltr"><<a href="mailto:ericbmerritt@gmail.com">ericbmerritt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Thats not possible at the moment. Dialyzer will do a good job at<br>
compile time warning you that something is wrong. I think thats about<br>
your best bet.<br>
<br>
Now, as I understand it this type information *is* retained in the<br>
compiled beam file. So you could possibly write something that will<br>
check the types for you, but I don't think it would be very<br>
performant.<br>
<br>
I think the right answer, at least with out more details, is to do a<br>
good job declaring specs and using them, while relying on dialyzer to<br>
tell you when there are problems.<br>
<div><div></div><div class="h5"><br>
On Tue, Jul 12, 2011 at 6:26 PM, Tristan Sloughter<br>
<<a href="mailto:tristan.sloughter@gmail.com">tristan.sloughter@gmail.com</a>> wrote:<br>
> I'm pretty sure this isn't possible but I wanted to be sure before working<br>
> around the lack of it.<br>
> if I have a type and record like:<br>
> -type password() :: binary().<br>
> -record(user, {username :: binary(),<br>
> password :: password()}.<br>
> At run time there is no way to tell a field is suppose to be of some type<br>
> during runtime, right?<br>
> Basically I'd like to be able to have generic or generated create functions<br>
> for records that may have to modify arguments (like a password has to be<br>
> encrypted from the string provided) when creating the record. So the create<br>
> function would pass each field, its value and its type to a transform<br>
> function that matches on type and returns the appropriately modified value.<br>
> Any ideas on how to do this with type definitions or do I need to use tuples<br>
> and an atom like {Type, Value} for the value of every field to achieve this?<br>
> Thanks,<br>
> Tristan<br>
</div></div>> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
><br>
</blockquote></div><br></div>