haskell - how to parse a uniprot-file with parsec? -


i newbie haskell, seems powerful language want learn. adopting code chapter in real world haskell on parsec. tried make own version of parsing content of uniprot-file. file consists of records (that starts ">"), , each record consists of lines. code seems close done in example, getting lot of errors - on types. exception among other taking output of readfile (io string) instead of string. appreciate if me understand wrong in approach...

import text.parsercombinators.parsec  main:: io()  parsesprot :: io string -> either parseerror [[string]]  parsesprot input = parse uniprotfile "(unknown)" input                uniprotfile = endby record eol         record = sepby lines (char '>')         lines = many (noneof ",\n")         eol = char '\n'  main =      parsesprot $ readfile "uniprot_sprot.fasta"      putstrln "hey" 

parsesprot doesn't need io in signature.

parsesprot :: string -> either parseerror [[string]] ... 

the result of readfile io string. can string binding result of readfile action new io action. in do notation can bind result variable <-

main =      filecontents <- readfile "uniprot_sprot.fasta" 

the parsesprot function doesn't return result in io, can use anywhere. in do notation tell difference between result bound variable , declaration using different syntax. x <- ... binds result variable. let x = ... declares x whatever on right hand side.

main =      filecontents <- readfile "uniprot_sprot.fasta"      let parsedcontents = parsesprot filecontents 

to test parser doing, might want print value returned parse.

main =      filecontents <- readfile "uniprot_sprot.fasta"      let parsedcontents = parsesprot filecontents     print parsedcontents 

without do notation can write

main = readfile "uniprot_sprot.fasta" >>= print . parsesprot 

>>= takes result of first computation , feeds function decide next.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -