0

In an exam i found this exercise: "Write a function that take a file name (i.e. "text.txt") and return a list of char without blanks"

For example:

"text.txt" contains "ab e ad c" the function must return -> [#"a",#"b",#"e",#"a",#"d",#"c"]

Which is the easiest way to solve the exercise?

I've tried to use the library "TextIO" and the function "input1" but i got stuck. I don't know how to implement the function recursively. Could someone help?

Community
  • 1
  • 1
Pater
  • 83
  • 1
  • 6

1 Answers1

1
fun chars filename =
  let
    val f = TextIO.openIn filename
    val s = TextIO.inputAll f
  in
    TextIO.closeIn f;
    List.filter (fn c => c <> #" ") (explode s)
  end
Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72