Introduction to ML – Part 1 Kenny Zhu. Assignment 2 chive/fall07/cos441/assignments/a2.ht m

Slides:



Advertisements
Similar presentations
More ML Compiling Techniques David Walker. Today More data structures lists More functions More modules.
Advertisements

ML Datatypes.1 Standard ML Data types. ML Datatypes.2 Concrete Datatypes  The datatype declaration creates new types  These are concrete data types,
Programming Languages Section 1 1 Programming Languages Section 1. SML Fundamentals Xiaojuan Cai Spring 2015.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Chapter ElevenModern Programming Languages1 A Fourth Look At ML.
CS 320: Compiling Techniques David Walker. People David Walker (Professor) 412 Computer Science Building office hours: after each.
Introduction to ML – Part 1 Frances Spalding. Assignment 1 chive/fall05/cos441/assignments/a1.ht m
Standard ML- Part I Compiler Baojian Hua
5/11/2015IT 3271 Types in ML (Ch 11) datatype bool = true | false; datatype 'element list = nil | :: of 'element * 'element list n Predefined, but not.
1 CS 312 – Lecture 28 Continuations –Probably the most confusing thing you’ve seen all semester… Course summary –Life after CS 312.
Standard ML- Part III Compiler Baojian Hua
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
CS 320: Compiling Techniques David Walker. People David Walker (Professor) 412 Computer Science Building office hours: after each.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
Introduction to ML You will be responsible for learning ML on your own. Today I will cover some basics Read Robert Harper’s notes on “an introduction to.
Last Time Introduction Course Logistics Introduction to ML Base Types Tuples and Records Functions & Polymorphism See Harper ’ s Intro to ML.
CS 320: Compiling Techniques David Walker. People David Walker (Professor) 412 Computer Science Building office hours: after each.
CS 320: Compiling Techniques David Walker. People David Walker (Professor) 412 Computer Science Building office hours: after each.
CS235 Languages and Automata Department of Computer Science Wellesley College Introduction to Standard ML Wednesday, September 23, 2009 Reading: Beginning.
ML Datatypes.1 Standard ML Data types. ML Datatypes.2 Concrete Datatypes  The datatype declaration creates new types  These are concrete data types,
CSE-321 Programming Languages Introduction to Functional Programming (Part II) POSTECH March 13, 2006 박성우.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
Introduction to Functional Programming and ML CS 331 Principles of Programming Languages.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
Chapter 9: Functional Programming in a Typed Language.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Error Example - 65/4; ! Toplevel input: ! 65/4; ! ^^ ! Type clash: expression of type ! int ! cannot have type ! real.
Today’s Agenda ML Development Workflow –Emacs –Using use –The REPL More ML –Shadowing Variables –Debugging Tips –Boolean Operations –Comparison Operations.
Cs776(Prasad)L6sml971 SML-97 Specifics SML/NJ 110.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2013.
CSE-321 Programming Languages Introduction to Functional Programming POSTECH March 8, 2006 박성우.
Programming Languages and Compilers (CS 421)
Principles of programming languages 12: Functional programming
Programming Languages
ML: a quasi-functional language with strong typing
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2017.
Nicholas Shahan Spring 2016
CSE 341: Programming Languages Section 1
CSE 341: Programming Langs
CSE341: Programming Languages Section 1
CSE341: Programming Languages Section 1
Programming Languages
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2018.
Agenda SML Docs First-Class Functions Examples Standard Basis
Functions, Patterns and Datatypes
CSE 341: Programming Languages Section 1
CSE 341 Section 5 Winter 2018.
Erik (Happi) Johansson Room:
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2018.
ML’s Type Inference and Polymorphism
CSE-321 Programming Languages Introduction to Functional Programming
Functions, Patterns and Datatypes
Functions, Patterns and Datatypes
ML’s Type Inference and Polymorphism
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
CSE-321 Programming Languages Introduction to Functional Programming
Functions, Patterns and Datatypes
CSE-321 Programming Languages Introduction to Functional Programming
ML’s Type Inference and Polymorphism
Functional Programming and Haskell
ML’s Type Inference and Polymorphism
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
Functions, Patterns and Datatypes
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Drew Wyborski Programming Languages
Functional Programming and Haskell
Presentation transcript:

Introduction to ML – Part 1 Kenny Zhu

Assignment 2 chive/fall07/cos441/assignments/a2.ht m chive/fall07/cos441/assignments/a2.ht m Due next Monday (Oct 1st)

Introduction to ML This lecture: some basics on the SML language and how to interact with the SML/NJ run time system Next lecture: implement more complex system using SML Resources: Robert Harper’s “Programming in Standard ML” Peter Lee’s “Notes on using SML/NJ systems” SML/NJ Basis Library See course webpage for pointers and info about how to get the software

Standard ML Standard ML is a general-purpose functional programming language with type checking and type inference Emphasizes applications of functions, not state changes and mutable data Support for Complex data structures Memory management like Java Large projects with many modules Advanced type system for error detection

ML Highlights Interactive Language Type in expressions Evaluate and print result Compile into binary as well Strongly-typed language Every expression has a type Functions as values Certain errors cannot occur Polymorphic types provide flexibility

ML Highlights High-level programming features Data types Pattern matching Exceptions Mutable data discouraged Modules and functors

Basic types and expressions Int: 3+5, 2*6, 100 div 2, 2-5, ~3 Real: , 100.0/3.0, ~1.5 Char: #”!” String “abc”, “hello” ^ “ “ ^ “world” Bool: true, false, (5>6), (3<>4), a andalso b, c orelse d Unit: ()

Data structures Tuple: (“george”, 35) Record: {name = “george”, age = 35} List: 1::(2::(3::(4::nil)))) 1::2::3::4::nil 1::2::3::4::[] [1,2,3,4] 1::2::[3,4]

Declaration val x = 5 let val a = 4 val b = 2 in a + b end fun succ x = x + 1 exception SomeException type complex_num = (real * real) val n = (3.0, 5.5) datatype number = Int of int | Real of real val n1 = Real ~8.0

Functions fun f (x, y) = x * y fun f x y = x * y (curried form) fn (x:int, y:int) :int => x * y val f = fn x y => x * y fun f pat_1 = exp_1 | f pat_2 = exp_2 | f pat_3 = exp_2 | f _ = exp_default

Other Useful Expressions if x>0 then x-1 else x+1 case num of Int x -> x div 2 | Real y -> y / 2.0 (expr_1; expr_2; …; expr_n) raise SomeException “Fatal Error” some_expr handle SomeExpection s => print s

When your program grows… Interactive mode is a good way to start learning and to debug programs, but… Type in a series of declarations into a “.sml” file - use “foo.sml” [opening foo.sml] … list of declarations with their types

Larger Projects SML has its own built in interactive “make” Pros: It automatically does the dependency analysis for you No crazy makefile syntax to learn Cons: May be more difficult to interact with other languages or tools

Compilation Manager % sml - OS.FileSys.chDir “ ~/courses/510/a2 ” ; - CM.make(); looks for “ sources.cm ”, analyzes dependencies [compiling … ] compiles files in group [wrote … ] saves binaries in./CM/ - CM.make ’ “ myproj/ ” (); specify directory sources.cm c.smlb.smla.sig Group is a.sig b.sml c.sml

SML/NJ Demo