4 ms·
His example of how things should work is pretty much 1:1 how the webhelpers.html library works in python: >>> from webhelpers.html import literal >>> p
by Shish2k 13y ago
His example of how things should work is pretty much 1:1 how the webhelpers.html library works in python:
>>> from webhelpers.html import literal
>>> p1, p2 = literal("<p>"), literal("</p>")
>>> foo = "foo&<bar>"
>>> type(p1)
<class 'webhelpers.html.builder.literal'>
>>> type(foo)
<type 'str'>
>>> p1 + foo + p2
literal(u'<p>foo&<bar></p>')
And yes, having this sort of thing implemented at the language level, in a generic way that can apply to HTML, SQL, and anything else would be wonderful.
While we're asking for ponies, I'd also like it if "costOfPieInDollars = distanceInMiles + angleInDegrees" would be an error (unless each part was explicitly cast to a compatible type, eg the base int)...
- john_fushi 13y agoI'm not sure I understand your last point. Do you desire for compilers to deduce the underlying type from the name of the variable or a type system that would let you create subtypes to give them additional contextual informations that the compiler would then use to enforce integrity?
- demetrius 13y agoWell, actually Kawa Scheme has a feature called quantities [1]. (+ 1cm 2m) equals to 201.0cm, (+ 1cm 2degr) throws an exception (degr has to be declared first, with (define-base-unit degr "Temperature")). To tell the truth, I’ve never found any use for this feature. [1] https://www.gnu.org/software/kawa/Quantities.html https://www.gnu.org/software/kawa/Quantities.html
- zokier 13y agoI'd imagine that such type/units system would be most useful in interactive use, like in WolframAlpha where the system has quite good "understanding" of units and how they should be applied to formulas.
- scott_s 13y agoIt would be very useful in production code as well - consider the case of the Mars Climate Orbiter: http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_f...
- scott_s 13y agoThe Boost.Units library for C++ does this: http://www.boost.org/doc/libs/1_53_0/doc/html/boost_units/Quick_Start.html http://www.boost.org/doc/libs/1_53_0/doc/html/boost_units/Qu... Some examples from the documentation: quantity<length> L = 2.0*meters; quantity<energy> E = kilograms*pow<2>(L/seconds); quantity<plane_angle> theta = 0.375*radians; quantity<dimensionless> sin_theta = sin(theta); quantity<plane_angle> thetap = asin(sin_theta); I figured Haskell's type system could also do this sort of thing, and it can. I found Dimensional: https://code.google.com/p/dimensional/ https://code.google.com/p/dimensional/, but I'm not sure if it's in standard use in the Haskell community. Examples: https://code.google.com/p/dimensional/wiki/IspExample https://code.google.com/p/dimensional/wiki/IspExample
- derleth 13y ago> I'd also like it if "costOfPieInDollars = distanceInMiles + angleInDegrees" would be an error Type tagging.