Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Reducing local variable duplication (Michael Orlitzky)
   2. Re:  Reducing local variable duplication (Michael Xavier)
   3. Re:  Reducing local variable duplication (Brent Yorgey)
   4.  some tools like .Net reflector? ( anyzhen )
   5. Re:  some tools like .Net reflector? (Claude Lee)
   6.  Help me improve my code (Neuman Vong)
   7. Re:  haskell error message (Sunil S Nandihalli)


----------------------------------------------------------------------

Message: 1
Date: Mon, 29 Aug 2011 11:35:50 -0400
From: Michael Orlitzky <[email protected]>
Subject: [Haskell-beginners] Reducing local variable duplication
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I have a series of unit tests like this,

> test_volume1 :: Assertion
> test_volume1 =
>   assertEqual "volume is correct" True (vol ~= (-1/3))
>   where
>     p0 = (0, -0.5, 0)
>     p1 = (0, 0.5, 0)
>     p2 = (2, 0, 0)
>     p3 = (1, 0, 1)
>     ...
> 
> test_volume2 :: Assertion
> test_volume2 =
>   assertEqual "volume is correct" True (vol ~= (1/3))
>   where
>     p0 = (0, -0.5, 0)
>     p1 = (2, 0, 0)
>     p2 = (0, 0.5, 0)
>     p3 = (1, 0, 1)
>     ...


I would like to de-duplicate some of the values in the 'where' clause.
Furthermore, I don't want to declare e.g. p0 and p3 at the top level,
since later tests may need different values of p0,p3. What I would
really like is something like the following. Is it possible?

> let p0 = (0, -0.5, 0)
>     p3 = (1, 0, 1)
> in
>   test_volume1 :: Assertion
>   test_volume1 =
>     assertEqual "volume is correct" True (vol ~= (-1/3))
>     where
>       p1 = (0, 0.5, 0)
>       p2 = (2, 0, 0)
>       ...
> 
>   test_volume2 :: Assertion
>   test_volume2 =
>     assertEqual "volume is correct" True (vol ~= (1/3))
>     where
>       p1 = (2, 0, 0)
>       p2 = (0, 0.5, 0)
>       ...




------------------------------

Message: 2
Date: Mon, 29 Aug 2011 10:53:08 -0700
From: Michael Xavier <[email protected]>
Subject: Re: [Haskell-beginners] Reducing local variable duplication
To: Michael Orlitzky <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <CANk=zmh9iqc92nufjcfzvvqlhxcv2wq8rt_oeqv0fqfkdk_...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

The where block takes precedence over the global scope so if these points
are generally reused for most tests and only deviate in a few, you could
define them globally to the file and then modify individual ones in the
where blocks of code that needs different values.

Hope that helps

On Mon, Aug 29, 2011 at 8:35 AM, Michael Orlitzky <[email protected]>wrote:

> I have a series of unit tests like this,
>
> > test_volume1 :: Assertion
> > test_volume1 =
> >   assertEqual "volume is correct" True (vol ~= (-1/3))
> >   where
> >     p0 = (0, -0.5, 0)
> >     p1 = (0, 0.5, 0)
> >     p2 = (2, 0, 0)
> >     p3 = (1, 0, 1)
> >     ...
> >
> > test_volume2 :: Assertion
> > test_volume2 =
> >   assertEqual "volume is correct" True (vol ~= (1/3))
> >   where
> >     p0 = (0, -0.5, 0)
> >     p1 = (2, 0, 0)
> >     p2 = (0, 0.5, 0)
> >     p3 = (1, 0, 1)
> >     ...
>
>
> I would like to de-duplicate some of the values in the 'where' clause.
> Furthermore, I don't want to declare e.g. p0 and p3 at the top level,
> since later tests may need different values of p0,p3. What I would
> really like is something like the following. Is it possible?
>
> > let p0 = (0, -0.5, 0)
> >     p3 = (1, 0, 1)
> > in
> >   test_volume1 :: Assertion
> >   test_volume1 =
> >     assertEqual "volume is correct" True (vol ~= (-1/3))
> >     where
> >       p1 = (0, 0.5, 0)
> >       p2 = (2, 0, 0)
> >       ...
> >
> >   test_volume2 :: Assertion
> >   test_volume2 =
> >     assertEqual "volume is correct" True (vol ~= (1/3))
> >     where
> >       p1 = (2, 0, 0)
> >       p2 = (0, 0.5, 0)
> >       ...
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Michael Xavier
http://www.michaelxavier.net
LinkedIn <http://www.linkedin.com/pub/michael-xavier/13/b02/a26>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110829/46c01c07/attachment-0001.htm>

------------------------------

Message: 3
Date: Mon, 29 Aug 2011 15:58:56 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Reducing local variable duplication
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Aug 29, 2011 at 11:35:50AM -0400, Michael Orlitzky wrote:
> since later tests may need different values of p0,p3. What I would
> really like is something like the following. Is it possible?
> 
> > let p0 = (0, -0.5, 0)
> >     p3 = (1, 0, 1)
> > in
> >   test_volume1 :: Assertion
> >   test_volume1 =
> >     assertEqual "volume is correct" True (vol ~= (-1/3))
> >     where
> >       p1 = (0, 0.5, 0)
> >       p2 = (2, 0, 0)
> >       ...
> > 
> >   test_volume2 :: Assertion
> >   test_volume2 =
> >     assertEqual "volume is correct" True (vol ~= (1/3))
> >     where
> >       p1 = (2, 0, 0)
> >       p2 = (0, 0.5, 0)
> >       ...

No, this is not possible directly.  You have several options. As
someone else already suggested, one option is to declare p0, p3 in the
global scope and then shadow them in any local scopes where you would
like them to have different values.  Another option might be to do
something like this:

[test_volume1, test_volume2] =
  [ let p1 = (0, 0.5, 0)
        p2 = (2, 0, 0)
    in  assertEqual "volume is correct" True (vol ~= (-1/3))
   
  , assertEqual "volume is correct" True (vol ~= (1/3))

  ...
  
  ]
  where p0 = ...
        p3 = ...

However, this is a bit brittle if you ever want to reorder the tests
or insert new tests, since you have to update the list of names and
list of test bodies to stay in sync.

Also, am I correct in assuming the above is actually a stripped-down
version of the real code?  p0, p1, p2... etc. do not actually show up
in the tests you have written at all.

-Brent



------------------------------

Message: 4
Date: Tue, 30 Aug 2011 12:07:33 +0800
From: " anyzhen " <[email protected]>
Subject: [Haskell-beginners] some tools like .Net reflector?
To: " beginners " <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

hi guys.


is it exists some tools in haskell platfrom, such like "reflector" or "DeAsmIL" 
in .Net platform ?


sometime get a compiled version without source code,and i don't know how 
explore it.


thanks any help.
jiangzhen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110830/7ddc9dca/attachment-0001.htm>

------------------------------

Message: 5
Date: Tue, 30 Aug 2011 12:30:30 +0800
From: Claude Lee <[email protected]>
Subject: Re: [Haskell-beginners] some tools like .Net reflector?
To: anyzhen <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <cakfuhxyeekqtyi81vcvbmyzxeuq97mdjor-go3ypj2wjxxd...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

Haskell code usually compiles to native code, which means it can decompile
to ASM, but not the original Haskell code, especially when optimization
applied. However, GHC can produce some sort of bytecode "using
LLVM<http://llvm.org/>as a backend", but I don't think it's designed
for production use. See
http://www.haskell.org/ghc/ for more details.

Thanks,
Claude

PS: License seems to be your first concern on the issue, not decompilers...
;)

2011/8/30 anyzhen <[email protected]>

> hi guys.
>
> is it exists some tools in haskell platfrom, such like "reflector" or
> "DeAsmIL" in .Net platform ?
>
> sometime get a compiled version without source code,and i don't know how
> explore it.
>
> thanks any help.
> jiangzhen
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110830/1520e454/attachment-0001.htm>

------------------------------

Message: 6
Date: Mon, 29 Aug 2011 21:52:28 -0700
From: Neuman Vong <[email protected]>
Subject: [Haskell-beginners] Help me improve my code
To: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"; Format="flowed";
        DelSp="yes"

Hi Haskell people,

I'm pretty new to Haskell still. There were a bunch of things I didn't
know how to do in the following script, I'm hoping some people on this
list can help with. For example, I had trouble returning an ExitCode
and using getProgName without getting a compile-time type error. I
feel like I'm doing something wrong with the Text/[Char] conversions
too. I'd also really appreciate any style tips. Thanks in advance!

{-# LANGUAGE OverloadedStrings #-}
module Main where

import System (getArgs)
import System.IO (hPutStrLn, stderr)
import Data.Text (pack, splitOn, length, isPrefixOf, Text)
import Prelude hiding (length)

data Rate = Rate Text Text deriving (Show)

findBestPrefix number rates = foldl1 longestPrefix $ matching rates
    where
        getLength rate = length $ getPrefix rate
        getPrefix (Rate prefix _) = prefix
        getPrice (Rate _ price) = price
        longestPrefix r1 r2 = if getLength r1 > getLength r2 then r1  
else r2
        matching rates = [ rate | rate <- rates, getPrefix rate
`isPrefixOf` number ]

makeRates = map $ \line ->
    let (prefix:rate:_) = splitOn ", " (pack line) in Rate prefix rate

main = getArgs >>= \args ->
    let findBest number rates = findBestPrefix number $ makeRates rates
    in case args of
        (arg:_) -> interact $ (++ "\n") . show . findBest (pack arg) .  
lines
        _ -> hPutStrLn stderr "Pass in a number as the first argument"


-- 
neuman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110829/ff436ec4/attachment-0001.htm>

------------------------------

Message: 7
Date: Tue, 30 Aug 2011 11:01:29 +0530
From: Sunil S Nandihalli <[email protected]>
Subject: Re: [Haskell-beginners] haskell error message
To: Daniel Fischer <[email protected]>,
        [email protected]
Message-ID:
        <cap0fd70xzybe-of5pe8vshq5cbukmkejbynxkdw_0t2noye...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks a lot Daniel.
Sunil.

On Mon, Aug 29, 2011 at 7:27 PM, Ozgur Akgun <[email protected]> wrote:

> Thanks a lot Daniel, great explanation!
>
> On 29 August 2011 14:49, Daniel Fischer 
> <[email protected]>wrote:
>
>> You have a function with three call patterns (and no previous constructor
>> specialisation), limit is 10, fine, specialise.
>>
>> This function calls a worker. Now, since we had three specialisations
>> above, the limit here is 10 `div` 3 = 3.
>> The worker would have four call patterns;
>> 4 > 3 => message "Hi there, I could have done more, but the limit said I
>> shouldn't. You might want to set a higher limit if you think it's
>> worthwhile to specialise."
>>
>
> Ozgur
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110830/b6c6f160/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 38, Issue 48
*****************************************

Reply via email to