I am new to programming and F# is my first .NET language.
I am attempting this problem on Rosalind.info. Basically, given a DNA string, I am supposed to return four integers counting the respective number of times that the symbols 'A', 'C', 'G', and 'T' occur in the string.
Here is the code I have written so far:
open System.IO
open System
type DNANucleobases = {A: int; C: int; G: int; T: int}
let initialLetterCount = {A = 0; C = 0; G = 0; T = 0}
let countEachNucleobase (accumulator: DNANucleobases)(dnaString: string) =
let dnaCharArray = dnaString.ToCharArray()
dnaCharArray
|> Array.map (fun eachLetter -> match eachLetter with
| 'A' -> {accumulator with A = accumulator.A + 1}
| 'C' -> {accumulator with C = accumulator.C + 1}
| 'G' -> {accumulator with G = accumulator.G + 1}
| 'T' -> {accumulator with T = accumulator.T + 1}
| _ -> accumulator)
let readDataset (filePath: string) =
let datasetArray = File.ReadAllLines filePath
String.Join("", datasetArray)
let dataset = readDataset @"C:\Users\Unnamed\Desktop\Documents\Throwaway Documents\rosalind_dna.txt"
Seq.fold countEachNucleobase initialLetterCount dataset
However, I received the following error message:
CountingDNANucleotides.fsx(23,10): error FS0001: Type mismatch. Expecting a DNANucleobases -> string -> DNANucleobases but given a DNANucleobases -> string -> DNANucleobases [] The type 'DNANucleobases' does not match the type 'DNANucleobases []'
What went wrong? What changes should I make to correct my mistake?
Array.mapshould bearray.iterand you need to return accumulator - John PalmerfoldthednaCharArrayarray, ascountEachNucleobaseexpects an accumulated value ofDNANucleobases, not an array. - Eugene Fotin