r/ATS • u/doublec • Dec 02 '17
Practical ATS
http://blog.vmchale.com/article/practical-ats
15
Upvotes
3
u/whatnot2 Dec 07 '17
I went a bit further to give a memory-clean implementation:
==15490== Memcheck, a memory error detector
==15490== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==15490== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==15490== Command: /tmp/./abcde_dats
==15490==
step_stream(.) = 22428
==15490==
==15490== HEAP SUMMARY:
==15490== in use at exit: 0 bytes in 0 blocks
==15490== total heap usage: 246,860 allocs, 246,860 frees, 150,169,910 bytes allocated
==15490==
==15490== All heap blocks were freed -- no leaks are possible
==15490==
==15490== For counts of detected and suppressed errors, rerun with: -v
==15490== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)There is some cheating due to the use of unsafe casting, which should not be hard to remove with a bit of additional effort. Or we could switch to reference-counted strings, which would make the code equally concise as the original one.
1
u/llogiq Dec 02 '17
I found it hard to follow the first example. There is a
bad_dirfunction, whereas later code uses agood_dircall. I don't have an ATS dev environment handy, so I cannot check if this is OK, but it sure looks like some half-done refactoring.