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.  to modify the eagerness level of haskell compiler..
      (Sunil S Nandihalli)
   2. Re:  to modify the eagerness level of haskell     compiler..
      (Sunil S Nandihalli)
   3. Re:  to modify the eagerness level of haskell     compiler..
      (Sunil S Nandihalli)
   4. Re:  Reducing local variable duplication (Michael Orlitzky)
   5. Re:  Help me improve my code (Antoine Latter)
   6. Re:  some tools like .Net reflector? ( anyzhen )
   7. Re:  Help me improve my code (Brent Yorgey)


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

Message: 1
Date: Tue, 30 Aug 2011 15:39:03 +0530
From: Sunil S Nandihalli <[email protected]>
Subject: [Haskell-beginners] to modify the eagerness level of haskell
        compiler..
To: beginners <[email protected]>
Message-ID:
        <CAP0FD72E=QMdDELK-Z58cfXbW4rjWNu=agnimsmyp6wskj_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi everybody,
 May be I am doing it wrong being a beginner.. but here is what I want.. I
am trying to debug a stack overflow problem by printing a lot using "trace"
commands. But it does not seem to seem to be printing in the expected order.
so it has been misleading quiet a bit. Can somebody guide me as to how to
modify the laziness of the program or some pointers on how to debug the
stack overflow errors.
Thanks in advance.
Sunil.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110830/42803bf5/attachment-0001.htm>

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

Message: 2
Date: Tue, 30 Aug 2011 15:42:04 +0530
From: Sunil S Nandihalli <[email protected]>
Subject: Re: [Haskell-beginners] to modify the eagerness level of
        haskell compiler..
To: beginners <[email protected]>
Message-ID:
        <CAP0FD71DNgLePpQ8WS7JuAGNMRhaWK8tg17ch=lqm0wdl9e...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

the code for the same can be found at https://github.com/sunilnandihalli/is2 it
is a single main.hs file so compilation is simply
* ghc main.hs --make*
thanks,
Sunil.

On Tue, Aug 30, 2011 at 3:39 PM, Sunil S Nandihalli <
[email protected]> wrote:

> Hi everybody,
>  May be I am doing it wrong being a beginner.. but here is what I want.. I
> am trying to debug a stack overflow problem by printing a lot using "trace"
> commands. But it does not seem to seem to be printing in the expected order.
> so it has been misleading quiet a bit. Can somebody guide me as to how to
> modify the laziness of the program or some pointers on how to debug the
> stack overflow errors.
> Thanks in advance.
> Sunil.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110830/0c49f63f/attachment-0001.htm>

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

Message: 3
Date: Tue, 30 Aug 2011 15:43:37 +0530
From: Sunil S Nandihalli <[email protected]>
Subject: Re: [Haskell-beginners] to modify the eagerness level of
        haskell compiler..
To: beginners <[email protected]>
Message-ID:
        <CAP0FD72u8Ld+gwkebU04PBjB0xc2J3=VC=gdyvjguh-exaa...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I failed to mention that the case I was trying it on is inp10.b.txt run it
as
main < inp10.b.txt
Sunil.

On Tue, Aug 30, 2011 at 3:42 PM, Sunil S Nandihalli <
[email protected]> wrote:

> the code for the same can be found at
> https://github.com/sunilnandihalli/is2 it is a single main.hs file so
> compilation is simply
> * ghc main.hs --make*
> thanks,
> Sunil.
>
>
> On Tue, Aug 30, 2011 at 3:39 PM, Sunil S Nandihalli <
> [email protected]> wrote:
>
>> Hi everybody,
>>  May be I am doing it wrong being a beginner.. but here is what I want.. I
>> am trying to debug a stack overflow problem by printing a lot using "trace"
>> commands. But it does not seem to seem to be printing in the expected order.
>> so it has been misleading quiet a bit. Can somebody guide me as to how to
>> modify the laziness of the program or some pointers on how to debug the
>> stack overflow errors.
>> Thanks in advance.
>> Sunil.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110830/0ad0167e/attachment-0001.htm>

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

Message: 4
Date: Tue, 30 Aug 2011 08:15:02 -0400
From: Michael Orlitzky <[email protected]>
Subject: Re: [Haskell-beginners] Reducing local variable duplication
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 08/29/2011 03:58 PM, Brent Yorgey wrote:
> 
> 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.


Correct, these are trivial cases. There is one expensive function that I
would like to avoid recomputing, but no simple examples I could give of it.

This is actually the solution that kmc gave me on #haskell, but my home
connection has been hurricaned and I haven't been able to reply. I
wouldn't mind the list/tuple solution otherwise; but, this is the best I
could come up with haddock-wise:

> -- | Check the value of c0030 for tetrahedron0 belonging to the cube
> --   centered on (1,1,1) with a grid constructed from the trilinear
> --   values. See example one in the paper.
> test_trilinear_c0030 :: Assertion    
> test_trilinear_c0030 = test_trilinear_c0030'
>                        
> [test_trilinear_c0030'] = [test_trilinear_c0030'']
>   where
>     g = make_grid 1 trilinear
>     cube = cube_at g 1 1 1
>     t = tetrahedron0 cube
>             
>     test_trilinear_c0030'' :: Assertion
>     test_trilinear_c0030'' =
>       assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)


It /works/, but gives me that "what the hell is he doing.." feeling when
re-reading my own code.



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

Message: 5
Date: Tue, 30 Aug 2011 08:19:08 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Help me improve my code
To: Neuman Vong <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
        <cakjsnqekmldcfcyx4zzdmp3jzro+qvhmfctuegha8qxsxao...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Mon, Aug 29, 2011 at 11:52 PM, Neuman Vong <[email protected]> wrote:
> 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!

What errors are you getting?

>
> {-# 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
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



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

Message: 6
Date: Tue, 30 Aug 2011 22:10:55 +0800
From: " anyzhen " <[email protected]>
Subject: Re: [Haskell-beginners] some tools like .Net reflector?
To: " Claude Lee " <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="gbk"

thank you
  
 
------------------ Original ------------------
From: "Claude Lee"; 
Date: 2011?8?30?(???) ??12:30
To: "anyzhen"; 
Cc: "beginners"; 
Subject: Re: [Haskell-beginners] some tools like .Net reflector?

 
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 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/047df510/attachment-0001.htm>

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

Message: 7
Date: Tue, 30 Aug 2011 10:48:05 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Help me improve my code
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Aug 29, 2011 at 09:52:28PM -0700, Neuman Vong wrote:
> 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!
> 

Hi Neuman,

This looks pretty good.  I'm not very familiar with the Text library,
so perhaps someone else can comment on the conversions between Text
and String.  But I can offer a few comments on style:

> {-# 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)

If you use record syntax:

  data Rate = Rate { getPrefix :: Text, getPrice :: Text }

then you get the selector functions getPrefix and getPrice for free
(so you don't have to write them in the 'where' clause below).

> 
> 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 ]

The matching function can also be implemented with a call to 'filter'. The
following three definitions are all equivalent, showing a progression
of simplification:

  matching rates = filter (\rate -> getPrefix rate `isPrefixOf` number) rates

  matching = filter (\rate -> getPrefix rate `isPrefixOf` number)

  matching = filter ((`isPrefixOf` number) . getPrefix)

At this point you could even inline the definition of matching if you
wanted.  You should use whichever of these definitions you find
clearest, I just wanted to show what is possible.

> 
> 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"

One general tip: it helps a lot, especially when learning, to give
explicit type signatures to all your top-level functions.  In fact, I
still do this.  I *first* write down a type signature, and *then*
write an implementation.  This may help you with your issues using
getProgName and and ExitCode, although without more information about
exactly what you were trying it's hard to know.

-Brent



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

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


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

Reply via email to