Random questions after a long haskell coding day
Hal Daume III
hdaume@ISI.EDU
Sat, 26 Jan 2002 21:36:17 -0800 (PST)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
---559023410-851401618-1012109777=:21641
Content-Type: TEXT/PLAIN; charset=US-ASCII
For your last question (about reduction to hnf), use the attached
code; search the haskell mailing list for "deepseq" for more.
--
Hal Daume III
"Computer science is no more about computers | hdaume@isi.edu
than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
On Sun, 27 Jan 2002, Jorge Adriano wrote:
>
>
> 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
---559023410-851401618-1012109777=:21641
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="DeepSeq.hs"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.GSO.4.21.0201262136170.21641@moussor.isi.edu>
Content-Description:
Content-Disposition: attachment; filename="DeepSeq.hs"
bW9kdWxlIERlZXBTZXEgd2hlcmUNCg0KY2xhc3MgIERlZXBTZXEgYSAgd2hl
cmUNCiAgZGVlcFNlcSA6OiBhIC0+IGIgLT4gYg0KICBkZWVwU2VxID0gc2Vx
ICA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