I wrote a program that turned out to be far too slow using lists so I'm trying to switch over to sequences. However, I can't seem to figure out the correct syntax after looking at the documentation.
So far I'm trying to learn with this simple code:
import Control.Monad
import qualified Data.Sequence as S
main :: IO ()
main = do
let testSeq = S.empty
testSeq S.|> 5
testSeq S.|> 20
testSeq S.|> 3
let newSeq = S.update 2 3 testSeq
let x = lookup 2 testSeq
print x
I've played around with the syntax for a while with no luck but it still has a ton of errors:
test.hs:9:8:
Couldn't match expected type ‘IO a0’
with actual type ‘S.Seq Integer’
In a stmt of a 'do' block: testSeq S.|> 5
In the expression:
do { let testSeq = S.empty;
testSeq S.|> 5;
testSeq S.|> 20;
testSeq S.|> 3;
.... }
In an equation for ‘main’:
main
= do { let testSeq = ...;
testSeq S.|> 5;
testSeq S.|> 20;
.... }
test.hs:10:8:
Couldn't match expected type ‘IO a1’
with actual type ‘S.Seq Integer’
In a stmt of a 'do' block: testSeq S.|> 20
In the expression:
do { let testSeq = S.empty;
testSeq S.|> 5;
testSeq S.|> 20;
testSeq S.|> 3;
.... }
In an equation for ‘main’:
main
= do { let testSeq = ...;
testSeq S.|> 5;
testSeq S.|> 20;
.... }
test.hs:11:8:
Couldn't match expected type ‘IO a2’
with actual type ‘S.Seq Integer’
In a stmt of a 'do' block: testSeq S.|> 3
In the expression:
do { let testSeq = S.empty;
testSeq S.|> 5;
testSeq S.|> 20;
testSeq S.|> 3;
.... }
In an equation for ‘main’:
main
= do { let testSeq = ...;
testSeq S.|> 5;
testSeq S.|> 20;
.... }
test.hs:13:25:
Couldn't match expected type ‘[(Integer, b)]’
with actual type ‘S.Seq a3’
Relevant bindings include x :: Maybe b (bound at test.hs:13:12)
In the second argument of ‘lookup’, namely ‘testSeq’
In the expression: lookup 2 testSeq
I'm new to Haskell so any help would be greatly appreciated!