Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

Dismiss

57 views

Skip to first unread message

Nov 29, 2015, 5:11:15 PM11/29/15

to

Mark Hayden wrote:

> let rec sum1_help a len ofs sum =

> if ofs < len then (

> sum1_help a len (succ ofs) (sum + a.(ofs))

> ) else (

> sum

> )

> ;;

>

> (* Does not allocate

> *)

> let sum1 a =

> let len = Array.length a in

> sum1_help a len 0 0

> ;;

This is just as fast and seems clearer:

let sum8 array =

let sum = ref 0 in

for i = 0 to (Array.length array) - 1 do

sum := !sum + array.(i)

done;

!sum ;;

> let rec sum1_help a len ofs sum =

> if ofs < len then (

> sum1_help a len (succ ofs) (sum + a.(ofs))

> ) else (

> sum

> )

> ;;

>

> (* Does not allocate

> *)

> let sum1 a =

> let len = Array.length a in

> sum1_help a len 0 0

> ;;

This is just as fast and seems clearer:

let sum8 array =

let sum = ref 0 in

for i = 0 to (Array.length array) - 1 do

sum := !sum + array.(i)

done;

!sum ;;

0 new messages

Search

Clear search

Close search

Google apps

Main menu