[erlang-questions] Type verification at runtime

Loïc Hoguin <>
Thu Sep 1 11:30:30 CEST 2016


A while ago I wrote https://github.com/extend/sheriff for doing just 
that. It hasn't been touched in a while so it probably doesn't work with 
all types / at all, but it should be a good start.

On 09/01/2016 11:27 AM, BOUDEVILLE Olivier wrote:
> Hello,
>
>
>
> Supposing that I have a “type-as-a-term” description as the one we can
> obtain from ASTs (ex: { type, 1, list,
> [{type,1,tuple,[{type,1,float,[]}, {type,1,boolean,[]}]} ] }, which
> corresponds to the "[{float(),boolean()}]" textual specification), is
> there a simple way to write a function telling, for such specified type
> and for any given term, whether this term is a value of that type?
>
> If it’s clearer, something akin to: -spec check_term_against_type(
> type_description(), term() ) -> boolean().
>
>
>
> Maybe some code already do that?
>
>
>
> Side question: is there already an “Erlang-official” convention to
> express types as terms, i.e the type_description() part ? I guess it
> would be probably inspired from the AST forms, yet removing line numbers
> and possibly (if feasible) the type/user_type distinction.
>
>
>
> Thanks in advance for any hint!
>
>
>
> Best,
>
>
>
> Olivier.
>
>
>
> Olivier Boudeville
> EDF R&D, Département SINETICS, Groupe ASICS, Bureau O2-E10
>
> 7, Boulevard Gaspard Monge, 91120 Palaiseau, France
>
> Tél. : +33 (0)1 78 19 43 63
>
> Tél. mobile : +33 (0)6 16 83 37 22
>
>
>
>
> Ce message et toutes les pièces jointes (ci-après le 'Message') sont
> établis à l'intention exclusive des destinataires et les informations
> qui y figurent sont strictement confidentielles. Toute utilisation de ce
> Message non conforme à sa destination, toute diffusion ou toute
> publication totale ou partielle, est interdite sauf autorisation expresse.
>
> Si vous n'êtes pas le destinataire de ce Message, il vous est interdit
> de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout
> ou partie. Si vous avez reçu ce Message par erreur, merci de le
> supprimer de votre système, ainsi que toutes ses copies, et de n'en
> garder aucune trace sur quelque support que ce soit. Nous vous
> remercions également d'en avertir immédiatement l'expéditeur par retour
> du message.
>
> Il est impossible de garantir que les communications par messagerie
> électronique arrivent en temps utile, sont sécurisées ou dénuées de
> toute erreur ou virus.
> ____________________________________________________
>
> This message and any attachments (the 'Message') are intended solely for
> the addressees. The information contained in this Message is
> confidential. Any use of information contained in this Message not in
> accord with its purpose, any dissemination or disclosure, either whole
> or partial, is prohibited except formal approval.
>
> If you are not the addressee, you may not copy, forward, disclose or use
> any part of it. If you have received this message in error, please
> delete it and all copies from your system and notify the sender
> immediately by return message.
>
> E-mail communication cannot be guaranteed to be timely secure, error or
> virus-free.
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang


More information about the erlang-questions mailing list