Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-vvkck Total loading time: 0 Render date: 2024-04-28T05:18:26.818Z Has data issue: false hasContentIssue false

10 - Text processing programs

Published online by Cambridge University Press:  05 May 2013

Michael R. Hansen
Affiliation:
Technical University of Denmark, Lyngby
Hans Rischel
Affiliation:
Technical University of Denmark, Lyngby
Get access

Summary

Processing text files containing structured data is a common problem in programming – you may just think of analysing any kind of textual data generated by electronic equipment or retrieved data from the web.

In this chapter we show how such programs can be made in a systematic and elegant way using F# and the .NET library. Data are extracted from text files using functions from the RegularExpressions library. The data processing of the extracted data is done with a systematic use of F# collections types list <′a>, Map <′a,′b> and Set<′a>. Easy access from F# programs to the extensive text processing features of the .NET library is given in a special TextProcessing library that can be copied from the home page of the book. The chapter centers on a real-world example illustrating the techniques.

Time performance of programs is always a problem, even with todays very fast computers. Poor performance of text processing programs is often caused by operations on very long strings. The method in this chapter uses three strategies to avoid using very long strings:

  1. 1. Text input is in most cases read and processed in small pieces (one or a few lines).

  2. 2. Text is generated and written in small pieces.

  3. 3. Large amounts of internal program data are stored in many small pieces in F# collections like list, set or map.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2013

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Text processing programs
  • Michael R. Hansen, Technical University of Denmark, Lyngby, Hans Rischel, Technical University of Denmark, Lyngby
  • Book: Functional Programming Using F#
  • Online publication: 05 May 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139093996.011
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Text processing programs
  • Michael R. Hansen, Technical University of Denmark, Lyngby, Hans Rischel, Technical University of Denmark, Lyngby
  • Book: Functional Programming Using F#
  • Online publication: 05 May 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139093996.011
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Text processing programs
  • Michael R. Hansen, Technical University of Denmark, Lyngby, Hans Rischel, Technical University of Denmark, Lyngby
  • Book: Functional Programming Using F#
  • Online publication: 05 May 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139093996.011
Available formats
×