Random questions after a long haskell coding day
Jorge Adriano
jadrian@mat.uc.pt
Sun, 27 Jan 2002 01:57:38 +0000
Am I the only one who'd like to have some the function specified by
> scan_and_fold f e xs= (scanl f e xs, foldl f e xs)
In the Lists library. Or is it there somewhere and I missed it?
What about:
> pair (f,g) x = (f x, g x)
> cross (f, g) = pair(f.fst, g.snd)
I kind of like point free style.
Any thumb rule for using arrays? I'm expecting access to be O(1), it is right?
Need to have a set of data, and I just want to get random elements from that
Set, arrays seem like a good solution... am I right?
DiffArrays... aren't they supposed to be just like Arrays expect for the (//)
behaviour (and accum and accumArray....), If so, why is there no Show
instance for them? Or Functor instance? When I tried to change to DiffArray
it broke everywhere...
Speaking of functors, in the Haskell98 Library Report:
"The two functions map and ixmap derive new arrays from existing ones (...)
The map function transforms the array values while ixmap allows for
transformations on array indices."
That is supposed to be fmap, not map right?
Unboxed types... Ghci
> f n = 3#
loads ok and,
Test> :t f
forall t. t -> PrelGHC.Int#
nice... now this:
> f :: Int -> Int#
> f n = 3#
when trying to load I get:
Test.hs:3: Type constructor or class not in scope: `Int#'
Failed, modules loaded: none.
What am I missing here? Tried Int#, PrelGHC.Int... nothing worked...
and Ghci also didn't know about (+#) either...
Last but not least, got this algorithm
w_(n+1) = w_(n) + deltaW
The ws and deltaW are vectors (lists). The deltaW is calculated using w_(n)
and some random point from a DataSet. So I'm doing something like
lstep :: TrainingSet->WeightVector->WeightVector
lstep ts w = w `vectorsum` deltaW
where
bla, bla
learn ::TrainSet->WeightVec->WeightVec
learn ts w0 = until p (lstep tSet) w0
where
bla, bla
[actually I'm making things a little more simple than they are... lstep
receives and returns a triple with the, w, stdGen to get the random val, n.
of steps...]
I'm having some stack overflows in my program and I think this is what's
causing it. The suspension in my calculated weight vectors... I should be
evaluating the weight vectors in each step... (agree?)
But how can I evaluate a whole list? seq or $! just reduce elements to head
normal form.
[Yes, I know I can always print them all! :-)
In fact, just to see if that was the cause I tried printing them right now...
Well I'd have to print 50000 results, and I'm short on disk space...
redirected the output to dev null and it is printing for about 40min now
still no stack overflow... ]
Also got this problem if I want to check evaluation times. I used to do it
something like this when calculating simple values:
> time1 <- getCPUTime
> val <- return $! f x
> time2 <- getCPUTime
But this doesn't work if val is a list of values. So how do you do it?
Wouldn't it be nice to have some strict 'lists'?
Once I asked why is aren't there any operators to reduce elements to their
normal form (not head normal), I was answered that for some types there is no
such concept... Is that because of the newtype declaration? (if it isn't I
think I'm missing something here... functions are in normal form, for
primitive datatypes it's the same as head normal form, and for constructed
datatypes you can define it by structural recursion...)
And now I'm off to bed
Thanks to those who actually read the whole mail :-)
J.A.