Question: let makeStream this state next = ( ( this , state ) , next ) ;; ( * FIRST. Return the first element of a
let makeStream this state next
this state next ;;
FIRST. Return the first element of a stream.
let first this state next
this ;;
REST. Return a stream with its first element removed.
let rest this state next
next this state, next ;;
TAKE. Return a list of the first COUNT elements TAKEn from STREAM.
let rec take count stream
match count
with
first stream :: take count rest stream ;;
NATURALS. A infinite stream of We don't use
STATE here, so we let it be the dummy unit object
let naturals
makeStream fun this state this ;;
let odds
let rec generateodd n makeStream n n fun this state this state, state in
generateodd ;;
let rec trim count stream
match count with
stream
trim count rest stream ;;
let rec scale factor stream
let newThis first stream factor in
let newState factor rest stream in
makeStream newThis newState fun restState scale factor restState
let rec sum left right
let combine stream streamfirst stream first streamrest stream rest stream in
makeStream combine left rightcombinefun sum rest leftrest right ;;
My error is a type mismatch error at:
let rec scale factor stream
let newThis first stream factor in
let newState factor rest stream in
makeStream newThis newState fun restState scale factor restState
makeStream newThis newState fun
expression has typeint int a int b ac int bint b ad
but an expression was expected of type d
The type variable d occurs inside
int int a int b ac int bint b ad
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
