• Tidak ada hasil yang ditemukan

User Defined Datatypes in SML

N/A
N/A
Protected

Academic year: 2024

Membagikan "User Defined Datatypes in SML"

Copied!
2
0
0

Teks penuh

(1)

User Dened Datatypes in SML

S. Arun-Kumar April 1, 2013

1. Generalize the example of resistance circuits done in the lecture notes, to include capacitors and inductors as well and write functions to determine various useful quantities such as the potential drop across a circuit and potential drops across individual sub-circuits etc. as a functions of the initial voltage across the entire circuit.

2. In the tautology-checker we had dened transformations of a proposition to conjunctive normal form (product of sums).

(a) Now give rewrite rules which transform a given proposition to dis- junctive normal form (sum of products).

(b) Working with user-dened datatypes themselves involves a fair amount of storage and the checking of constructors. It is more ecient to represent a proposition as a list of lists of ordered pairs of positive atoms and negative atoms. Dene the data type datatype literal

= POS of string | NEG of string Write a function convert: Prop -> literal list list to convert a proposition into this form.

(c) Now re-design the tautology-checker for the above representation.

(d) A proposition is a contradiction if for all truth assignments to the atoms it is false. How would you go about designing a contradiction checker?

3. We may dene a datatype called digraph with nodes of some type 'node as a list of pairs, where each pair consists of a node of type 'node and a list of successor nodes. Such a data-type is useful for modelling and analysing circuits of active and passive components, transportation prob- lems (consisting of the various Metro lines, DTC bus routes etc).

(a) Write down this datatype denition

(b) Write a function succ: digraph * node -> node list which pro- duces the list of successor nodes.

(c) Write a function paths: digraph * node * node -> node list list which produces the list of all paths from a given node to another given node in a digraph.

1

(2)

(d) If there are any cycles in the digraph, then the answer to the previous problem is an innite number of paths. Modify your answer so that in no path no node occurs more than once.

4. For each of the datatypes given in the above problems dene an appropri- ate map function which applies a unary functionf to each of the smallest conponents of the data type.

2

Referensi

Dokumen terkait