Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

SMAL for ML Programming - Lab 2005 | CECS 424, Lab Reports of Computer Science

Material Type: Lab; Class: Organization of Programming Lang; Subject: Computer Engr & Computer Sci; University: California State University - Long Beach; Term: Fall 2005;

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-6nf-1
koofers-user-6nf-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download SMAL for ML Programming - Lab 2005 | CECS 424 and more Lab Reports Computer Science in PDF only on Docsity! CECS 424 Lab on 9/13/05 Do the following: 1. Start SML for ML programming. 2. Learn to program with patterns in ML. Type each of the following lines and see what happens: a) Simple Patterns fun f _ = “yes”; (* _ is a pattern that matches anything *) f 34.5; (* use the above function *) f []; f (1, 2, 3); fun f x = “yes”; (* an alternative way of defining f that introduces an unused variable *) f 34.5; (* use the above function *) f []; f (1, 2, 3); fun f 0 = “yes”; (* pattern is a constant *) f 0; f 1; b) Complex Patterns fun f [a, _] = a; (* pattern is a list of exactly 2 items *) f [ #”H”, #”K”]; f [ #”H” ]; f ( #”H”, #”K” ); fun f (x::xs) = x; (* pattern is any non-empty list *) f [1, 2, 3]; f [ #”H”, #”K”]; f [ #”H” ]; f ( #”H”, #”K” ); c) Multiple Patterns fun f 0 = “zero” | f 1 = “one”; f 0; f 1; f 2; fun f 0 = “zero” | f _ = “non-zero”; f 0; f 2; f (2); f (1, 2); f [1, 2]; fun f n = if n = 0 then “zero” else “non-zero”; (* an alternative definition using a variable *) f 0; f 2; f (2); f (1, 2); f [1, 2];
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved