User loginNavigation |
archivesAlgebraic Data Types in JavaScriptIt is generally known that JavaScript supports a functional style of programming. But because it does not have algebraic data types, the functional programming is usually limited to some simple higher order functions applied to Arrays. I have often build small libraries that allow working with some aspects of algebraic data types in JavaScript. This time I thought is was cool enough to write a bit about it: Algebraic Data Types in JavaScript It includes:
I also show how to do the Data Types à la carte style of Wouter Swierstra with this library. SWI-Prolog FFI Problem: Getting Prolog and C to work together on MacOS?Hi, It seems that there are some issues with the foreign function interface specifically on MacOS. The Prolog manual has a very nice example of how to use FFI with C (http://gollem.science.uva.nl/SWI-Prolog/Manual/foreignxmp.html)... which this doesn't work for me on MacOS, but worked fine under Linux (Ubuntu 8.04 Hardy). I don't understand what's wrong with 'strlen' initially: $ gcc -I/opt/local/lib/swipl-5.6.15/include -fpic -c lowercase.c ... and even though we do get an object file in the end, we can't create (and register?) a library at the next step (this seems to be the MacOS-specific problem): $ gcc -shared -o lowercase.so lowercase.o Any suggestions? I couldn't find anything online except http://www.phil.uu.nl/~xges/HOWTO/swipldynlib.html which seems quite old? Should I go for it anyway? Thank you, Higher-order type constructor polymorphism vs./and template style specializationI'm wondering if there are language implementations that (elegantly?) combine what Scala (at least) refers to as "higher-order type constructor polymorphism" with the code specialization capabilities of C++ style templates? I don't mean the notion of "specialization" sometimes used to generically describe how instantiating a template List[int] will (likely) generate new code. I mean programmer driven template specialization. That's pretty much the question, so now I'll make a fool of myself trying to come up with an example. class Vector[T](size:int, init:T) extends Sequence[T] So Iterable, say, has methods like map and friends that will now return Vector[U] for some function (T => U). And all the Iterator and Builder machinery comes out nicely typed. Yada yada yada. Now, it would be *really* nice to somehow be able to implement bit vectors with custom code. Making up a silly keyword: specialize class Vector[Bool](.... We don't really want a vector of 32 bit Bool values! We want some custom bitwise code over an array of bytes or unsigned ints or something. We'll also need specialized Iterators[Vector[Bool]] (hopefully inlined) and associated machinery. But in the end we get a usable bit vector class (1) with much better space/speed for Vector[Bool] and (2) we can still write code like this. def somefun(vi:Vector[Int]): Vector[Bool] = vi.map((_ % 2 == 0)); Just a dumb and obvious example. We could also inquire about method (or function) specializations on values yada yada yada. Hence my question - are there language implementations that nicely combine their elegant type systems with the power of template style code specialization? Sorry if this is too implementation oriented a question. Scott |
Browse archivesActive forum topics |
Recent comments
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago
44 weeks 3 days ago
48 weeks 5 days ago
50 weeks 2 days ago
50 weeks 2 days ago
1 year 6 days ago
1 year 5 weeks ago
1 year 5 weeks ago