Programming in SML - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Programming in SML

Description:

'adam', 'drinks', 'beer', 'sometimes') ('word', 23, 3.14159) Lists ... [1,2,3,4] ['adam', 'plays', 'Xbox'] Lists vs Tuples. What's the difference? Lists vs Tuples ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 13
Provided by: webhome2
Category:
Tags: sml | adam | programming

less

Transcript and Presenter's Notes

Title: Programming in SML


1
Programming in SML
2
Standard ML
  • A functional language originally proposed by
    Robin Milner
  • Many implementations / compilers / interpreters
    exist for the language
  • We will be using the SML/NJ (Standard ML of New
    Jersey) interpreter

3
Why SML?
  • Polymorphic type inference
  • Pattern matching
  • The real reason
  • Because it's awesome!

4
Well then...
  • Let's write some code....

5
Dynamic vs Static Typing
  • In Scheme we didn't specify the types of data
    items
  • In Java we do specify the type
  • The two languages have completely different
    approaches to assigning types to data items

6
Dynamic vs Static Typing (cont)
  • Dynamic typing (Scheme) do not determine the
    type of a variable/binding until runtime
  • Static typing (Java) determine the type of a
    variable/binding at compile-time
  • Which is better?

7
Why SML? (revisited)
  • In SML, we didn't specify types either, is it
    statically or dynamically typed?

8
Type Inference
  • SML is statically typed, but all types are
    inferred by the context of the code.
  • Recall fun foo x x 3 SML will assign x to
    be of type int.
  • Why? How

9
Tuples
  • A tuple in SML is just like the mathematical
    construct of the same name
  • An ordered sequence of objects that is finite in
    size
  • (2, 5, 10, 18, 75)
  • (adam, drinks, beer, sometimes)
  • (word, 23, 3.14159)

10
Lists
  • Just like most functional languages, SML has
    strong native support for lists of items
  • Lists in SML are homogeneous
  • All elements must be the same type
  • Ex
  • 1,2,3,4
  • adam, plays, Xbox

11
Lists vs Tuples
  • What's the difference?

12
Lists vs Tuples
  • Lists can only contain items of the same type
  • Tuples can contain items of different types
Write a Comment
User Comments (0)
About PowerShow.com