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. Re:  File I/O: reading from, writing to, (Doug McIlroy)
   2.  Subject: Re:  File I/O: reading from, writing to, (Doug McIlroy)
   3. Re:  Couldn't match expected type ?IO ()? with actual type
      [Integer] (YCH)
   4.  recursion problem. (Roelof Wobben)
   5. Re:  recursion problem. (YCH)
   6. Re:  recursion problem. (Marcin Mrotek)


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

Message: 1
Date: Thu, 05 Feb 2015 18:14:55 -0500
From: Doug McIlroy <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] File I/O: reading from, writing to,
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

        same file in one function
> I strongly urge you to use the
proper way with temp file and renaming, even making it a function if you
need to repeat this several times

The "proper way" is fraught with pitfalls: potentially changes in
file ownership and permissions, loss of linkage when the file is
known by multiple names, and even total failure if you don't have


The proper way does have one safety advantage. The original file
is highly likely to survive should the writing of the new contents
stop prematurely for some external reason.

Doug


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

Message: 2
Date: Thu, 05 Feb 2015 18:28:46 -0500
From: Doug McIlroy <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Subject: Re:  File I/O: reading from,
        writing to,
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

        same file in one function
One more safety feature in the "proper way": in most systems it will
guarantee that a concurrent reader sees a coherent file image.

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

> I strongly urge you to use the
proper way with temp file and renaming, even making it a function if you
need to repeat this several times

The "proper way" is fraught with pitfalls: potentially changes in
file ownership and permissions, loss of linkage when the file is
known by multiple names, and even total failure if you don't have
write permission on the directory.^C

The proper way does have one safety advantage. The original file
is highly likely to survive should the writing of the new contents
stop prematurely for some external reason.

Doug


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

Message: 3
Date: Fri, 06 Feb 2015 15:06:34 +0900
From: YCH <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
        with actual type [Integer]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed

Hello, Roelof.

Your function is done. But it should be named 'toDigitsReversed' or so. 
So if you could write another 'reverse' function then you can compose 
like this.

toDigits = reverse . toDigitsReversed

-- 
YCH



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

Message: 4
Date: Fri, 06 Feb 2015 10:25:59 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] recursion problem.
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Hello,

I have figured out how I can make from 123   [1,2,3]

I did it this way :

-- | convert a number to a array in pieces where a negative number will 
be a empty array.
toDigits :: Integer -> [Integer]
toDigits n
    | n <= 0 = []
    | otherwise = toDigits (n `div` 10) ++ [n `mod` 10]


but now when I do toDigits 0 , I see [] as output where I was expected [0]

But when I do  toDigits 100 I see the right output [ 1,0,0]  which 
surprises me because I tought that with the first 0 there will be a []

Or is the n the second time [0,0]  and the thirth time [0] So it will be 
like this :

toDigits 100

to Digits [1] ++ [ 0,0]
toDigits [1] ++ [0] ++  [0]

which leads to [1,0,0]

Roelof



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

Message: 5
Date: Fri, 06 Feb 2015 19:06:56 +0900
From: YCH <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] recursion problem.
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed

On Fri, Feb 6, 2015 at 6:25 PM, Roelof Wobben <[email protected]> wrote:
> Hello,
> 
> I have figured out how I can make from 123   [1,2,3]
> 
> I did it this way :
> 
> -- | convert a number to a array in pieces where a negative number 
> will be a empty array.
> toDigits :: Integer -> [Integer]
> toDigits n
>    | n <= 0 = []
>    | otherwise = toDigits (n `div` 10) ++ [n `mod` 10]
> 
> 
> but now when I do toDigits 0 , I see [] as output where I was 
> expected [0]
> 
> But when I do  toDigits 100 I see the right output [ 1,0,0]  which 
> surprises me because I tought that with the first 0 there will be a []
> 
> Or is the n the second time [0,0]  and the thirth time [0] So it will 
> be like this :
> 
> toDigits 100
> 
> to Digits [1] ++ [ 0,0]
> toDigits [1] ++ [0] ++  [0]
> 
> which leads to [1,0,0]

toDigits 100
toDigits 10 ++ [0]
toDigits 1 ++ [0] ++ [0]
[1] ++ [0] ++ [0]
[1,0,0]

toDigits 0
[] -- because first guard clause

0 is valid input. It should be dealt different from negative number.

-- 
YCH






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

Message: 6
Date: Fri, 6 Feb 2015 11:27:56 +0100
From: Marcin Mrotek <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] recursion problem.
Message-ID:
        <CAJcfPznrN0-=5v8ix_B=xxyM1=PRVL5CNyeZTrPdQuJUKdN=v...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Ah, sorry, I didn't think of that when I responded to your other
thread. You can always insert a check before recursion:

toDigits :: Integer -> [Integer]
toDigits n
 | n < 0 = []
 | otherwise =  (if n' > 0 then toDigits n' else []) ++ [n `mod` 10]
     where n' = n `div` 10

Regards,
Marcin Mrotek


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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 80, Issue 8
****************************************

Reply via email to