My Blog

My WordPress Blog

Tag: SML


  • So. SML lets you redefine basic operators on basic types

    For instance, I could do this- fun op-(x,y) = x+y This makes the ‘-’ operator do integer addition.  Reals?  Hah, no subtracting them now!  Fails type checking on anything but ints. I can also do: fun op-(x) = ~x; Now, the ‘-’ operator does nothing except spawn error messages wherever it is used.  Well, wherever…


  • Functional Programming- Currying

    Some confusing stuff, but I’m starting to see the potential.   Currying is a technique that lets you define a function taking multiple arguments as a series of functions that take one argument, and returns a function that takes the rest.  You can define it all the way to the last argument. This lets you…


  • SML is odd

    (if exp1 then exp2 else exp3) div (if exp4 then exp5 else exp6) Is valid and for at least some problems, is entirely reasonable. I think the key to SML, at least so far… *everything* is an expression.  Any complete statement returns a value, and anything that returns a value counts as an expression.  Ok,…


  • Euclid algorithm for Greatest common Denominator, SML

    fun gcd (x,y) = if y = 0 then x else gcd(y, x mod y) I’ve wondered how to easily do this in code, without having to brute force it.  Turns out Euclid worked out the algorithm over 2,000 years ago. Even if you aren’t a programmer, you can probably follow this code if you…


  • Project Euler problem 1- SML Implementation

    Finished the current assignments and lectures for my Programming Languages course on Coursera, so I figured I’d go and do some other stuff in ML.  ML is a functional language, very heavy on recursion among other fun differences from imperative and OO languages. Here’s a solution to Project Euler problem 1, summing all multiples of…