diff --git a/src/elf_section_header_table.lem b/src/elf_section_header_table.lem index bf808c1..6661d16 100644 --- a/src/elf_section_header_table.lem +++ b/src/elf_section_header_table.lem @@ -638,7 +638,7 @@ let rec read_elf32_section_header_table' endian bs0 = else read_elf32_section_header_table_entry endian bs0 >>= fun (entry, bs1) -> read_elf32_section_header_table' endian bs1 >>= fun sht -> - return (sht ++ [entry]) + return (entry :: sht) (** [read_elf64_section_header_table' ed bs0] parses an ELF64 section header table * from byte sequence [bs0] assuming endianness [ed]. Assumes [bs0] is of the @@ -653,7 +653,7 @@ let rec read_elf64_section_header_table' endian bs0 = else read_elf64_section_header_table_entry endian bs0 >>= fun (entry, bs1) -> read_elf64_section_header_table' endian bs1 >>= fun sht -> - return (sht ++ [entry]) + return (entry :: sht) (** [read_elf32_section_header_table sz ed bs0] parses an ELF32 section header * table from a [sz] sized prefix of byte sequence [bs0] assuming endianness diff --git a/src/error.lem b/src/error.lem index 90f946b..b75df28 100644 --- a/src/error.lem +++ b/src/error.lem @@ -86,14 +86,14 @@ let rec repeatM' count seed action = action seed >>= fun (head, seed) -> repeatM' (count - 1) seed action >>= fun (tail, seed) -> return (head::tail, seed) - + (** [mapM f xs] maps [f] across [xs], failing if [f] fails on any element of [xs]. *) val mapM' : forall 'a 'b. ('a -> error 'b) -> list 'a -> error (list 'b) -> error (list 'b) -let rec mapM' f xs acc = +let rec mapM' f xs rev_acc = match xs with - | [] -> acc - | x::xs -> mapM' f xs (acc >>= fun tl -> f x >>= fun hd -> return (hd::tl)) + | [] -> rev_acc >>= fun rev_acc -> return (List.reverse rev_acc) + | x::xs -> mapM' f xs (rev_acc >>= fun tl -> f x >>= fun hd -> return (hd::tl)) end val mapM : forall 'a 'b. ('a -> error 'b) -> list 'a -> error (list 'b)