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: How can I fix this 'where' error ? (S. H. Aegis)
2. Trying to grasp Monads - IO and delayed actions (John M. Dlugosz)
3. Re: iterated function value sequence (John M. Dlugosz)
4. Re: What does "(# #)" mean? (John M. Dlugosz)
5. Re: Trying to grasp Monads - IO and delayed actions
(Sylvain Henry)
----------------------------------------------------------------------
Message: 1
Date: Sun, 6 Apr 2014 09:38:07 +0900
From: "S. H. Aegis" <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How can I fix this 'where' error ?
Message-ID:
<CAJp-NqxCqGD-7SFDzz9wv=dfsyimyb-ndm8fszc6t_ohmzq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
It's work !
Thank you so much !
I change my editor settings as you said.
Thank you again, and Have a nice day.
S. Chang
2014-04-06 9:18 GMT+09:00 Bob Ippolito <[email protected]>:
> The problem is that you are mixing tabs and spaces. It doesn't realize
> that the two lines are supposed to be at the same level of indentation.
> It's best to always use spaces, never tabs.
>
> This might be easier to avoid if you put where on its own line, but the
> best solution is to configure your text editor to always expand tabs to
> spaces.
>
>
> On Sat, Apr 5, 2014 at 5:13 PM, S. H. Aegis <[email protected]> wrote:
>
>> Hi.
>> I'm new to Haskell. I try to solve Euler Project for studying Haskell
>> through Googling, reading books.
>> There is a error in where sentence, but I can't fix this.
>>
>> maxEleList :: String -> String -> [Int]
>> maxEleList xs ys = maxOfTwo upperList lowerList
>> where upperList = map turpleSum $ zip (toIntList xs) (toIntList ys)
>> lowerList = map turpleSum $ zip (toIntList xs) (tail $ toIntList ys)
>>
>> Error message is
>> ~/maxPathSum.hs: line 4, column 75:
>> Parse error
>> Error message:
>> Parse error: =
>> Code:
>> maxEleList xs ys = maxOfTwo upperList lowerList
>> where upperList = map turpleSum $ zip (toIntList xs) (toIntList ys)
>> > lowerList = map turpleSum $ zip (toIntList xs) (tail $ toIntList
>> ys)
>>
>>
>> How can I fix this?
>> Thank you for your kind help.
>>
>> S. Chang
>>
>>
>> ----------------
>> This code is for Euler project: problem 18, and whole code is like
>> this... (Not yet finished...)
>>
>> maxEleList :: String -> String -> [Int]
>> maxEleList xs ys = maxOfTwo upperList lowerList
>> where upperList = map turpleSum $ zip (toIntList xs) (toIntList ys)
>> lowerList = map turpleSum $ zip (toIntList xs) (tail $ toIntList ys)
>> maxOfTwo :: [Int] -> [Int] -> [Int]
>> maxOfTwo [] [] = []
>> maxOfTwo (x:xs) (y:ys) = max x y : maxOfTwo xs ys
>>
>> turpleSum :: (Int, Int) -> Int
>> turpleSum (x, y) = x + y
>>
>> toIntList :: String -> [Int]
>> toIntList = map (\x -> read x :: Int) . words
>>
>> rowData :: [[Int]]
>> --rowData = reverse $ map (map (\x -> read x :: Int) . words) [r1, r2,
>> r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15]
>> rowData = map (map (\x -> read x :: Int) . words) [r1, r2, r3, r4, r5,
>> r6, r7, r8, r9, r10, r11, r12, r13, r14, r15]
>>
>> r1 = "75"
>> r2 = "95 64"
>> r3 = "17 47 82"
>> r4 = "18 35 87 10"
>> r5 = "20 04 82 47 65"
>> r6 = "19 01 23 75 03 34"
>> r7 = "88 02 77 73 07 63 67"
>> r8 = "99 65 04 28 06 16 70 92"
>> r9 = "41 41 26 56 83 40 80 70 33"
>> r10 = "41 48 72 33 47 32 37 16 94 29"
>> r11 = "53 71 44 65 25 43 91 52 97 51 14"
>> r12 = "70 11 33 28 77 73 17 78 39 68 17 57"
>> r13 = "91 71 52 38 17 14 91 43 58 50 27 29 48"
>> r14 = "63 66 04 68 89 53 67 30 73 16 69 87 40 31"
>> r15 = "04 62 98 27 23 09 70 98 73 93 38 53 60 04 23"
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
Sok Ha, CHANG
Dr. Chang's Clinic. #203. 503-23. AmSa-Dong, GangDong-Gu, Seoul.
Tel: +82-2-442-7585
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140406/86a3e95c/attachment-0001.html>
------------------------------
Message: 2
Date: Sun, 06 Apr 2014 02:41:41 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Trying to grasp Monads - IO and delayed
actions
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
A spiral approach to learning: you understand, then you learn more, and then
you are more
confused than ever.
I recall that a function in the IO Monad just combines actions to make a big
action list,
and doesn't actually do the side-effect-laden "work" until it is later
triggered, normally
because the program is defined to evaluate main.
Depending on the time of day and which example I pick, I can sometimes follow
what's
"really happening" in the definition of >>=. But here are some specific
questions:
In <http://www.haskell.org/haskellwiki/Monads_as_computation>
> What is a for-each loop really? It's something which performs some action
> based on each
> element of a list. So we might imagine a function with the type:
>
> forM :: (Monad m) => [a] -> (a -> m b) -> m [b]
>
> (as an added bonus, we'll have it collect the results of each iteration).
>
> We can write this with sequence and map:
>
> forM xs f = sequence (map f xs)
>
> we apply the function to each element of the list to construct the action for
> that
> iteration, and then sequence the actions together into a single computation.
>
So map by itself produces a [m b]. Why does it need to be turned into m [b]?
What does
the 'sequence' accomplish, other than restructuring the results that already
exist?
The reason I asked about (#?#) is because I wanted to see what IO was really
doing, to see
what the difference was between using >>= initially and then somehow "cranking"
it later.
<http://hackage.haskell.org/package/base-4.6.0.1/docs/src/GHC-Base.html#%3E%3E%3D>
lists
> instance Monad IO where
> {-# INLINE return #-}
> {-# INLINE (>>) #-}
> {-# INLINE (>>=) #-}
> m >> k = m >>= \ _ -> k
> return = returnIO
> (>>=) = bindIO
> fail s = failIO s
>
> returnIO :: a -> IO a
> returnIO x = IO $ \ s -> (# s, x #)
>
> bindIO :: IO a -> (a -> IO b) -> IO b
> bindIO (IO m) k = IO $ \ s -> case m s of (# new_s, a #) -> unIO (k a) new_s
>
> thenIO :: IO a -> IO b -> IO b
> thenIO (IO m) k = IO $ \ s -> case m s of (# new_s, _ #) -> unIO k new_s
>
> unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
> unIO (IO a) = a
where bindIO is the function of interest. In a chain of commands, getLine
might be the
'k' argument to bindIO. Somewhere there's a real machine function called to do
the
reading from the file, right?
------------------------------
Message: 3
Date: Sun, 06 Apr 2014 02:44:34 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] iterated function value sequence
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 4/5/2014 10:55 AM, Bob Ippolito wrote:
> Now, how might I do something like that but "forget" previous values to
> free up memory?
>
>
> Garbage Collection does that for you. If all the references are gone, the
> memory can be
> freed. If you have a specific use in mind I can show you what that looks like.
>
>
Say,
zz = abs <$> numerator <$> iterate (\x->x^2-7%4) 0
and at some point I
print $ zz!!30
How does the GC know that I'll never refer to zz!!n again where n < 30 ?
------------------------------
Message: 4
Date: Sun, 06 Apr 2014 02:51:49 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What does "(# #)" mean?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 4/5/2014 10:31 AM, Christopher Allen wrote:
>
> Search I used to get your answer:
> http://symbolhound.com/?q=tuple+%28%23+%23%29+Haskell
Thanks. That is more helpful than "sure it works!". I had tried searches like
<http://symbolhound.com/?q=%28%23>
Since Emanuel was confused by my meta-quoting of syntax in prose, is there some
(other)
standard that's used in this mailing list when using plain text without markup?
It's not just Google, BTW. I can't search PDF files either. The search bar on
www.haskell.org itself gives "no results" and other things (I forget what) have
even given
syntax error!
------------------------------
Message: 5
Date: Sun, 6 Apr 2014 11:20:24 +0200
From: Sylvain Henry <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Trying to grasp Monads - IO and
delayed actions
Message-ID:
<CAPmptcX9DaHd6_JikhsAsj+LWHtJtFY=rx3zdq23jb7v+y7...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
[IO b] is a list of functions that perform side-effects. You can remove
elements of the list, add new ones, change the order of the elements, etc.
All of these operations are pure because you do not execute side-effecting
functions: you just manipulate a list. When you use "sequence" on it and
get a "IO [b]", you build a single function that calls every function of
the previous list in sequence (think ";" in imperative programming
languages) and returns their results in a list. As long as you don't call
it, no side-effect occurs.
The IO monad is used to ensure that side-effecting functions are performed
in a deterministic order and are not mixed up with pure code. See my
introduction in [1], maybe it can help you understand the motivation and
the code in GHC.Base where RealWorld is used explicitly.
Cheers
Sylvain
[1]
http://www.sylvain-henry.info/home/data/uploads/talks/shenry-2013-02-05-haskell-intro.pdf(from
slide 20)
2014-04-06 9:41 GMT+02:00 John M. Dlugosz <[email protected]>:
> A spiral approach to learning: you understand, then you learn more, and
> then you are more confused than ever.
>
> I recall that a function in the IO Monad just combines actions to make a
> big action list, and doesn't actually do the side-effect-laden "work" until
> it is later triggered, normally because the program is defined to evaluate
> main.
>
> Depending on the time of day and which example I pick, I can sometimes
> follow what's "really happening" in the definition of >>=. But here are
> some specific questions:
>
> In <http://www.haskell.org/haskellwiki/Monads_as_computation>
>
> What is a for-each loop really? It's something which performs some action
>> based on each
>> element of a list. So we might imagine a function with the type:
>>
>> forM :: (Monad m) => [a] -> (a -> m b) -> m [b]
>>
>> (as an added bonus, we'll have it collect the results of each iteration).
>>
>> We can write this with sequence and map:
>>
>> forM xs f = sequence (map f xs)
>>
>> we apply the function to each element of the list to construct the action
>> for that
>> iteration, and then sequence the actions together into a single
>> computation.
>>
>>
> So map by itself produces a [m b]. Why does it need to be turned into m
> [b]? What does the 'sequence' accomplish, other than restructuring the
> results that already exist?
>
> The reason I asked about (#?#) is because I wanted to see what IO was
> really doing, to see what the difference was between using >>= initially
> and then somehow "cranking" it later.
>
> <http://hackage.haskell.org/package/base-4.6.0.1/docs/src/
> GHC-Base.html#%3E%3E%3D> lists
>
>> instance Monad IO where
>> {-# INLINE return #-}
>> {-# INLINE (>>) #-}
>> {-# INLINE (>>=) #-}
>> m >> k = m >>= \ _ -> k
>> return = returnIO
>> (>>=) = bindIO
>> fail s = failIO s
>>
>> returnIO :: a -> IO a
>> returnIO x = IO $ \ s -> (# s, x #)
>>
>> bindIO :: IO a -> (a -> IO b) -> IO b
>> bindIO (IO m) k = IO $ \ s -> case m s of (# new_s, a #) -> unIO (k a)
>> new_s
>>
>> thenIO :: IO a -> IO b -> IO b
>> thenIO (IO m) k = IO $ \ s -> case m s of (# new_s, _ #) -> unIO k new_s
>>
>> unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
>> unIO (IO a) = a
>>
>
> where bindIO is the function of interest. In a chain of commands, getLine
> might be the 'k' argument to bindIO. Somewhere there's a real machine
> function called to do the reading from the file, right?
>
>
>
>
> _______________________________________________
> 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/20140406/6f4b4ed7/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 70, Issue 12
*****************************************