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:  What does "(# #)" mean? (Kim-Ee Yeoh)
   2. Re:  Definition of last: why complicate it? (Dimitri DeFigueiredo)
   3.  How can I fix this 'where' error ? (S. H. Aegis)
   4. Re:  How can I fix this 'where' error ? (Bob Ippolito)


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

Message: 1
Date: Sat, 5 Apr 2014 23:14:13 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] What does "(# #)" mean?
Message-ID:
        <capy+zdqmu-x9gg5ov9utnrdpv-4uneftbpowmb1bpjbpjpv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Sat, Apr 5, 2014 at 10:31 PM, Christopher Allen <[email protected]>wrote:

> The user meant unboxed tuples, not a literal string. Try not to give the
> questioner the benefit of the doubt and search for a better answer than,
> "there's quotes, it must be a string rather than them trying to contain the
> syntax they want to express!"


Hey, we're all here for the learning, and I for one am always
discombobulated on discovering how much English I have left to learn.

I think Emmanuel was perplexed and understood the question as best as he
could.

John, on the other hand, could probably have followed the question about
the curious brackets by supplying context e.g. "And I found it here like
this (# Int, Int #)."

And everyone, (me especially!), please use the mailing list wisely to
maintain good vibes.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140405/7e9f5703/attachment-0001.html>

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

Message: 2
Date: Sat, 05 Apr 2014 11:11:43 -0600
From: Dimitri DeFigueiredo <[email protected]>
To: [email protected]
Cc: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Definition of last: why complicate
        it?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Daniel,

Thanks so much for the detailed explanations!
I got it now.

:-D

Dimitri


Em 04/04/14 17:23, Daniel Fischer escreveu:
> On Friday 04 April 2014, 15:55:57, Dimitri DeFigueiredo wrote:
>> Hi Daniel,
>>
>> I really like your translation of ulast' below
>>
>> ulast' y ys = case ys of
>>                   [] -> y
>>                   z:zs -> ulast' z zs
>>
>> This makes it really clear there is only one comparison happening. I
>> tried looking
>> at core with the -O option (ghc 7.6.3), but am having a had time making
>> sense of it.
> I'll add explanations between the core below.
>
>> For comparison, could you also translate the inefficient version of plast
>> into the case notation you use above?
> GHC already did that, I'll put it next to the core at the bottom.
>
>>
>> Thanks,
>>
>> Dimitri
>>
>> ==================== Tidy Core ====================
>> Result size of Tidy Core = {terms: 49, types: 58, coercions: 0}
>>
>> lvl_rgS :: [GHC.Types.Char]
>> [GblId]
>> lvl_rgS = GHC.CString.unpackCString# "empty list!"
>>
>> Test.ulast2 :: forall a_b. a_b
>> [GblId, Str=DmdType b]
>> Test.ulast2 = \ (@ a_b) -> GHC.Err.error @ a_b lvl_rgS
> All of the above is uninteresting, apart from some stats at the header line,
> we have the error call in case the function is called with an empty list.
>
> What follows is the code for the worker ulast', named ulast1 in the core.
>
>> Rec {
>> Test.ulast1 [Occ=LoopBreaker] :: forall a_b. a_b -> [a_b] -> a_b
> ulast1is a loop-breaker, it cannot be inlined (it is recursive, thus it cannot
> be inlined anyway), but that need not interest at the moment. Its type is
>
> a -> [a] -> a
>
> but GHC added a suffix to get unique identifiers. You can suppress that with
> the flag -dsuppress-uniques
>
>> [GblId, Arity=2, Caf=NoCafRefs, Str=DmdType LS]
> It takes two arguments, doesn't refer to any CAFs, and is lazy in the first
> argument, strict in the second.
>
>> Test.ulast1 =
>>     \ (@ a_b) (y_aeQ :: a_b) (ds_df8 :: [a_b]) ->
> The arguments. First is the type at which it is called, then come
> - the last list element we have found so far, y_aeQ, and
> - the remaining part of the list, ds_df8.
>
>>       case ds_df8 of _ {
> The list argument is evaluated (to weak head normal form), but it is never
> referred to later as a whole, hence it's not bound to an identifier, so we
> have a wild-card `_` after the `case ... of`
>
>>         [] -> y_aeQ;
> Totally Haskell, if the remaining part of the list is empty, return the last
> element, otherwise
>   
>>         : y1_aeR ys_aeS -> Test.ulast1 @ a_b y1_aeR ys_aeS
> remember the next list element and recur. In core, we have unparenthesised
> prefix application also of infix operators, so the match that in Haskell looks
>
>      y1_aeR : ys_aeS
>
> looks a bit different in core, but is recognisable.
>   
>>       }
>> end Rec }
> Now comes the code for the wrapper. That's not recursive, hence we don't have
> the "Rec" annotations, and it's not a loop-breaker, it can be inlined. The
> type signature is clear, with an explicit forall.
>   
>> Test.ulast :: forall a_aeH. [a_aeH] -> a_aeH
>> [GblId,
>>    Arity=1,
>>    Str=DmdType S,
> It takes one argument and is strict in that argument, next comes unfolding
> info, in case it shall be inlined elsewhere, that doesn't need to interest us
> now.
>
>>    Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=1, Value=True,
>>            ConLike=True, WorkFree=True, Expandable=True,
>>            Guidance=IF_ARGS [30] 50 0}]
>> Test.ulast =
>>     \ (@ a_b) (ds_df6 :: [a_b]) ->
> The type at which ulast is called, and the argument it is passed
>
>>       case ds_df6 of _ {
> The list is evaluated (to WHNF),
>
>>         [] -> Test.ulast2 @ a_b;
> If the list is empty, call error
>
>>         : x_aeN xs_aeO -> Test.ulast1 @ a_b x_aeN xs_aeO
> Otherwise call the worker
>
>>       }
>>
>> lvl1_rgT :: forall a_d. a_d
>> [GblId, Str=DmdType b]
>> lvl1_rgT = \ (@ a_d) -> GHC.Err.error @ a_d lvl_rgS
> Another error call, this time to be called from plast
>
>> Rec {
>> Test.plast [Occ=LoopBreaker] :: forall a_aeI. [a_aeI] -> a_aeI
> plast is recursive, a loop-breaker (no inlining possible), and its type
>
>> [GblId, Arity=1, Str=DmdType S]
> it takes one argument, and is strict in it
>
>> Test.plast =
>>     \ (@ a_d) (ds_dfc :: [a_d]) ->
>>       case ds_dfc of _ {
> The list is evaluated
>
>>         [] -> lvl1_rgT @ a_d;
> If it is empty, call error,
>
>>         : x_aeJ ds1_dfd ->
> otherwise, bind the first element and the tail to names
>
>>           case ds1_dfd of wild1_X8 {
> and evaluate the tail. The tail may be referenced later, hence the evaluated
> tail is bound to a name - wild1_X8.
>
>>             [] -> x_aeJ;
> If the tail is empty, return the first (only) element of plast's argument
>
>>             : ipv_sfz ipv1_sfA -> Test.plast @ a_d wild1_X8
> otherwise recur on the tail.
>
>>           }
>>       }
>> end Rec }
> The Haskell case-construct corresponding to the core is
>
> plast :: [a] -> a
> plast xs = case xs of
>               [] -> error "empty list!"
>               y:ys -> case ys of
>                         [] -> y
>                         z:zs -> plast ys
>
>



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

Message: 3
Date: Sun, 6 Apr 2014 09:13:29 +0900
From: "S. H. Aegis" <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] How can I fix this 'where' error ?
Message-ID:
        <CAJp-Nqwf=L=abkhkhzq32v-o9pxybodypxh_bkzyg_qngeu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140406/f9f5ef6d/attachment-0001.html>

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

Message: 4
Date: Sat, 5 Apr 2014 17:18:14 -0700
From: Bob Ippolito <[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:
        <cacwmpm9a4qtvfuuhmf4nv_n9wzrhyh2s2aix04ewngxeipz...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140405/6c0e09b9/attachment.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 70, Issue 11
*****************************************

Reply via email to