The Miranda Programming Language
description
Transcript of The Miranda Programming Language
![Page 1: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/1.jpg)
The Miranda Programming LanguagePRESENTED BY SEAN KAUFFMAN
D. A. TURNER AN OVERVIEW OF MIRANDA , SIGPLAN NOTICES 21(12):158-166, DECEMBER 1986. PDF [139K]
![Page 2: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/2.jpg)
Designer
Developed in 1985 by David Turner
Professor in the School of Computer Science and Engineering at California State University
Currently teaching Game Programming CSE 441
![Page 3: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/3.jpg)
Language Developed
It was produced by Research Software Ltd. of England and was the first purely functional language to be commercially supported. Miranda was first released in 1985, as a fast interpreter in C for Unix-flavor operating systems, with subsequent releases in 1987 and 1989.
The later Haskell programming language is similar in many ways to Miranda.
![Page 4: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/4.jpg)
Historical Background
Miranda is a modern functional programming language designed by David Turner of the University of Kent, with lazy evaluation, polymorphic strong typing, and a powerful module system.
A program written in Miranda is typically 5 to 15 times shorter than the corresponding program in C or Java.
Windows XP
0 5 10 15 20 25 30 35 40 45 50
Full length 5 times smaller 15 times smaller
![Page 5: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/5.jpg)
Types of Applications Non-Strict functional Language : Program works under
the concept of lazy evaluation. (pass equation till need it the do “work”) Advantage? Can pass large data structures
Purely Functional : Excludes destructive modifications. Why is this desired? Think Space saving
Thesaurus: instead of copy for every person you can make a custom sub list for each person on their own modifications and still have them access the main thesaurus.
![Page 6: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/6.jpg)
Features
Purely Functional - no side effectsHigher Order - supports functional dataLazy - supports non strict functions and
infinite data objectsList ComprehensionsPolymorphic Strong TypingAbstract Data Types and Modules
![Page 7: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/7.jpg)
Features: Higher Order
Ability for it’s functions to do one of the following.Take 1 or more functions as inputOutput a function
![Page 8: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/8.jpg)
Features: List Comprehensions
Syntactic construct available for creating a list based on existing lists.
[n * n | n <- [1..100] ]
![Page 9: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/9.jpg)
Features: Polymorphic Strong Typing That is, every expression and every sub
expression has a type, which can be deduced at compile time, and any inconsistency in the type structure of a script results in a compile time error message.
Primitive types - Number, Boolean, and Char.
![Page 10: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/10.jpg)
Features:Abstract Data Types and ModulesMiranda permits the definition of abstract types, whose implementation is "hidden" from the rest of the program.To show how this works we give the standard example of defining stack as an abstract data type :abstype stack * with empty :: stack *
isempty :: stack * -> bool push :: * -> stack * -> stack * pop :: stack * -> stack * top :: stack * -> *
stack * == [*] empty = [] isempty x = (x=[]) push a x = (a:x) pop (a:x) = x top (a:x) = a
![Page 11: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/11.jpg)
Examples 1 : Primes
1. Primes = Sieve [2..]2. Sieve (p:x) = p : Sieve [n | n <- x; n mod p
~= 0]
![Page 12: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/12.jpg)
Example 2 : Fibonacci
1. Fibs = map fib [0..]2. Fib 0 = 03. Fib 1 = 14. Fib (n + 2) = Fibs! (n + 1) + Fibs! N5. Test = layn (map shownum Fibs)
![Page 13: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/13.jpg)
Language Basics : List
Week_days = [“Mon”, “Tue”, “Wed”, “Thur”, “Fri”]
Days = Week_days ++ [“Sat”, “Sun”]
[“Mon”, “Tue”, “Wed”, “Thur”, “Fri”] -- [“Mon”, “Wed”] is [“Tue”, “Thur”, “Fri”]
![Page 14: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/14.jpg)
Language Basics: Guard
Gcd a b = gcd (a-b) b, if a > b = gcd a (b-a), if a < b
= a, if a = b
The last guard in such a series of alternatives can be written "otherwise", instead of "if condition", to indicate a default case(*).
![Page 15: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/15.jpg)
Language Basics: Currying
answer = twice twice suc suc twice suc 0 twice f x = f (f x) suc x = x + 1
![Page 16: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/16.jpg)
Language Basics: Tuples
A sequence of elements of mixed type is called a Tuple.
Store = (“Starbucks”, False, True, 20) Employee = (“Timmy”, True, True, 40)
Accessing the elements of a tuple is also done by pattern matching. You can create definitions such as… Fst (a, b) = a Snd (a. b) = b
![Page 17: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/17.jpg)
Compiler Part 1
![Page 18: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/18.jpg)
Compiler Part 2
![Page 19: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/19.jpg)
Compiler Part 3
![Page 20: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/20.jpg)
Compiler Part 4
1. Fibs = map fib [0..]2. Fib 0 = 03. Fib 1 = 14. Fib (n + 2) = Fibs! (n + 1) + Fibs! N5. Test = layn (map shownum Fibs)
![Page 21: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/21.jpg)
Compiler Part 5
![Page 22: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/22.jpg)
Compiler Part 6
1332
![Page 23: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/23.jpg)
CompilerPart 7
![Page 24: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/24.jpg)
Compiler Part 8
![Page 25: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/25.jpg)
Current State
Last update: 22 December 2010
Last release in 2008
![Page 26: The Miranda Programming Language](https://reader031.fdocuments.us/reader031/viewer/2022020106/56816931550346895de07e64/html5/thumbnails/26.jpg)
SummeryDesigned and excels at fast prototyping.
If you are interested in working with tuples I would recommend that you take a look at this language on a curiosity standpoint.
It is mainly implemented on Unix systems.