smlnj - What are the options Some and None SML? -
I am new to sml (and programming, in fact).
List of fun reading (infile: string) = val in = TextIO.openIn infile funny loop INS = case textIO.inputLine = some row => Line :: loop ins | None = & gt; [] TextIO.close In the loop ins before these endings;
This is a program I saw here. How to use nothing else and how to use 'first'
option
data type is used if there is a valid value There is a possibility of something.
For example,
fun split xy = if y == 0 then nothing else (x / y)
Can be used when it is necessary to handle a special case of zero-partition without taking the exception of exceptions.
TextIO.inputLine
return none
is nothing to read, and some A
, where L
that line is read, when there is.
first
is less important (the lowest of all) the infix function which first evaluates toward its left hand, then towards the right hand, and then returns to the left hand is. Br> type in 'a - & gt; Unit - & gt; A '
, i.e., is used only on the right hand side for its side effects.
In this case, this code makes it more and more readable (and functional-looking)
funny reedlist (infel: string) = val in = textio. Open Infile Fun Loop Indata = Case TextIioITIf you have some line of indhat = & gt; Line :: Loop Indara | None = & gt; [] TextIO.closeIn results in = loop ins; Result end
Comments
Post a Comment