TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Idris: Type safe printf [video]

54 pointsby kenhtyover 10 years ago

7 comments

brontyover 10 years ago
You can check format strings in Java at compile-time using the Checker Framework: <a href="http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#formatter-checker" rel="nofollow">http:&#x2F;&#x2F;types.cs.washington.edu&#x2F;checker-framework&#x2F;current&#x2F;che...</a><p>The format string semantics are actually pretty tricky because printf will perform conversions in certain cases.
latkinover 10 years ago
Very cool, Idris looks like a really interesting language.<p>F#&#x27;s standard printf-family functions are all type-safe in exactly the same way. This requires special support by the compiler, though, as F#&#x27;s type system is not as powerful. Most of the plumbing is standard, but the conversion from string literal to PrintfFormat at compile time is only possible due to hardcoded magic. You can&#x27;t get exactly the same effect from plain user code, though you could certainly get something very close using a Type Provider (the syntax would just be a bit clunkier).
评论 #8807391 未加载
ufoover 10 years ago
Why define Format as<p><pre><code> data Format = FInt Format | FString Format | FOther Char Format | FEnd </code></pre> instead of using lists?<p><pre><code> data FormatPart = FInt | FString | FOther Char type Format = List FormatPart</code></pre>
评论 #8806310 未加载
wheatiesover 10 years ago
This was awesome and yet one more reason to learn Idris. Now I have to see if it can be done in Scala.
评论 #8806442 未加载
wz1000over 10 years ago
Really cool, but I am assuming printf only works for values which are determined at compile time?
评论 #8806255 未加载
ExpiredLinkover 10 years ago
Idris?
评论 #8805850 未加载
socceroosover 10 years ago
My mind immediately went to Star Citizen...
评论 #8806161 未加载