Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Miranda: A non-strict functional language with polymorphic types (1985) [pdf] (psu.edu)
95 points by tjalfi on May 3, 2017 | hide | past | favorite | 37 comments


Being introduced to Miranda was a revelation to me back in the day. I still prefer aspects of Miranda syntax over Haskell. For example, the formatting of guards in Miranda:

  gcd a b = gcd (a-b) b, if a>b
          = gcd a (b-a), if a<b
          = a,           if a=b
versus Haskell

  gcd a b | a>b  = gcd (a-b) b
          | a<b  = gcd a (b-a)
          | a==b = a
I know it's a small thing and you can get used to such differences but since FP became just an occasional side interest for me, I never made the switch as a heavyish Miranda user to Haskell. For a long time even getting a Haskell compiler to run was a massive pain.

So I started using Mark Jones' Gofer[1] interpreter which was trivial to build and still is 20 years later assuming you can find the source tar ball. It kept the nicer syntax of Miranda and added most of the power features of Haskell. I particularly liked the generalized list comprehension feature which really should have made it into Haskell; things like combinator parser code reads beautifully with it.

I know it's what you're used to but Haskell code always looks ugly to me in comparison to Miranda or Gofer.

[1] https://en.wikipedia.org/wiki/Gofer_(programming_language)


I agree that Haskell guards are aesthetically uglier, but they're much easier to read with the conditional before the result.


Someday the equivalence between the notations will make it possible to (gasp) automagically translate between the two. If we're still typing programs.


And then we'll have AST wars instead of language wars... unless we can compile to and from Turing machine instructions :-D


Hopefully we skip that AST phase and go directly more meaningful and still less visual related layer. Is it called ASG or something.

Edit: We probably have wars anyway but I think after that our wars are about something that really matters.


I found the Miranda version much easier to read. But then I'm a mathematician who has never used Haskell, and it's fairly similar to how mathematicians write multi-line functions.


It's mentioned in the Wikipedia article that monad comprehensions are available as a GHC language extension


I vaguely seem to remember that the designer's of Haskell picked a different syntax for guards to make the language look less like Miranda. Miranda was owned by a private company (IIRC) and they didn't want to run the risk of infringing on their IP. But I don't know if that's really true.


If you like "if guards", and want a non-whitespace delimited, strict, dynamically typed language, check out the Pure language:

    gcd a b = gcd (a-b) b if a>b;
            = gcd a (b-a) if a<b;
            = a           otherwise;
https://agraef.github.io/pure-lang/


It's funny you posted this, because today was examination day for the 'Functional Programming in Miranda' course at University College London, one of the last institutions to actually teach a course in Miranda.

Indeed, it's a great stepping stone to Haskell, with many of the important functional concepts but without some advanced (albeit useful) stuff like monadic programming.

One of the downsides is the ancient Mira console, which can output cryptic error messages, and which doesn't have command history out the box. Nevertheless, it's lightyears faster to start than GHCI, so good for learning.


> and which doesn't have command history out the box

SML/NJ had the same issue; you can use rlwrap[0] to fix that.

[0]: https://linux.die.net/man/1/rlwrap


The University of Windsor used it in their first year intro to CS course up until 2015. I wonder how many other places still use it.


Yup I learned it there. It's there for the basics of CS like learning recursion they don't really mention if it is functional tbh.


Interesting, is Haskell used in many universities?


Multiple universities (at least Utrecht and Nijmegen) in the Netherlands use Haskell for teaching functional programming, and I believe some FP research is also carried out there using Haskell.


Radboud University actually switched to Haskell this year, now that Ralf Hinze is teaching the functional programming course. Before they used to teach Clean (which is not that different from Haskell).


UCL teaches other courses using Haskell (http://www.cs.ucl.ac.uk/students/syllabus/undergrad/101p_pri...), and Imperial College London uses it for teaching functional programming too (http://www.imperial.ac.uk/computing/current-students/courses...).


Oxford also taught a few courses in Haskell:

- Functional Programming - Digital Systems - Principals of Programming Languages.

Compilers was primarily in OCaml, and there were several other courses in Scala.


UT Austin used Haskell as the intro freshman language until pressure from large regional donors/employers caused them to switch to Java in the early 2000s.


I'm not sure, honestly. It would be nice if it were.


If you enjoyed this paper than I highly encourage you to read Wadler's 'Why calculating is better than scheming' where in he critiques SICP for it's choice of using Scheme, arguing that Miranda would have been a better language to go with.

https://www.cs.kent.ac.uk/people/staff/dat/miranda/wadler87....


Interesting, I've read this before but it connects to some things I've been thinking about and discussing with people recently. A comment I made earlier today was about the value of static/expressive type systems, and how that can let you quickly go from specification -> code. My point being the relatively short semantic distance between many specification languages and the type systems in Ada/Haskell/others.

You get a similar effect in connecting between intent and code when using a more algebraic language versus the Algol-lineage and Lisp-lineage languages. You reduce the semantic distance (especially paired with a good type system from above) from your specification to your executable code.


I agree in terms of pure utility that that makes a lot of sense. You basically spec it out via setting up types.

But in the context on SICP I'm not sure that would be ideal. As that book is about teaching 101 programming by introducing you to the idea of black box abstraction and building a program through layers of abstraction.

Starting with types would be an entirely different approach to go at it.

So personally, in my ideal university, I'd prefer to learn Scheme/LISP as the 101 course introduction to programming and learn a Haskell-esque language the following term and thereafter.

Although that being said, I used a practical language as my introduction to programming (Ruby) before diving into SICP - which really taught me programming. So maybe it's worth going with practical first, then diving into the theoretical underpinning so you fully appreciate and grasp what you are doing.


We used Miranda in my first year intro to CS course back in 2006. It was still used at my university up until last year. Others may disagree, but I feel that it's a fine language for teaching fundamental CS concepts like recursion/induction, formal reasoning about your programs, data types, etc.


This took me back. It was the first language taught to us in Computer Science at UNSW (1989).

I remember the first lecture went something along the lines of "Ok, all you smart arses who've mucked around at home with BASIC and think you can program. We're going to teach you Miranda!"


Ditto. That was the first language I was taught at UNSW (in 1993). It was quite a change from the BASIC, assembler, and C I had taught myself in high-school.


This talk by David Turner gives a good overview of the development of "lazy, strongly typed, polymorphic, higher order, purely functional languages" https://www.youtube.com/watch?v=QVwm9jlBTik It touches on Miranda from 35:00.


Thanks for posting this, as someone who poked around functional languages for years, this lecture really pulled together a lot of ideas. Im amazed at the ability of a good teacher (world class even) to illuminate complex subjects.


Miranda was used as the implementation language for the "Implementing functional languages: a tutorial"[0] book co-authored by SPJ. The book is well constructed (and free).

[0]: https://www.microsoft.com/en-us/research/publication/impleme...


Had a taste of both Miranda and Prolog in my college programming languages course (2000?). Miranda made it much easier for me to reason about C++ templates a few years later when C++ compilers finally started getting better.


I learned Miranda at SFU way back in the 90's. It was a language way ahead of its time back then. I'm glad to see that so many languages nowadays have some of the stuff I worked with in Miranda.


Also reminiscent of OCaml, which is taught in the introductory sequence of CS classes at Harvard (CS51). Introducing CS students to functional programming early on is valuable for distancing Computer Science, the field, from the mechanics of programming.

Also pretty sure that the CS51 class is sponsored by Jane Street Capital (one of the few companies in the world that uses the language!).


Few? Well, that is of course relative, but I have worked in at least 3 companies where ocaml has been used in parts of the company codebase.


Haskell godmother right ?


Yep. I think the licence was a barrier to the sort of research that Haskell has been subject to. Probably misremembering a podcast with SPJ tho.



Look, Ma, it is Haskell.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: