Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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


Today's Topics:

   1.  How to tell haskell that 'a' is 'a' ? (Lai Boon Hui)
   2. Re:  How to tell haskell that 'a' is 'a' ? (Sylvain Henry)
   3. Re:  Equivalence (or not) of lists (Chris Sasarak)


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

Message: 1
Date: Mon, 14 Nov 2016 10:15:23 +0800
From: Lai Boon Hui <laibo...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] How to tell haskell that 'a' is 'a' ?
Message-ID:
        <cajdqggn8_8wa7uvr2+0cwazzdek+mglkrh1pnuwowomne+s...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi all,

skips :: [a] -> [[a]]
skips xs = go 1 [] where
  go :: Int -> [[a]] -> [[a]] *-- Compiles if i remove this line*
  go n acc
    | n > (length xs) = acc
    | n == 1 = xs : (go (n+1) acc)
    | n < 1 = []
    | otherwise = (everyN n xs) : (go (n+1) acc)

everyN :: Int -> [a] -> [a]
everyN n xs =
  case (drop (n-1) xs) of
    y:ys -> y : (everyN n ys)
    [] -> []

How can i tell haskell compiler that a is the sub program if the same as a
in the main program?


-- 
Best Regards,
Boon Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20161114/53a1ad11/attachment-0001.html>

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

Message: 2
Date: Mon, 14 Nov 2016 03:26:27 +0100
From: Sylvain Henry <sylv...@haskus.fr>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to tell haskell that 'a' is 'a' ?
Message-ID: <3178e490-9884-676d-843a-162e29288...@haskus.fr>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi,

Use ScopedTypeVariables and forall:

{-# LANGUAGE ScopedTypeVariables #-}

skips :: forall a. [a] -> [[a]]
skips xs = go 1 [] where
    go :: Int -> [[a]] -> [[a]]
*   ...*

Sylvain

On 14/11/2016 03:15, Lai Boon Hui wrote:
> Hi all,
>
> skips :: [a] -> [[a]]
> skips xs = go 1 [] where
>   go :: Int -> [[a]] -> [[a]] *-- Compiles if i remove this line*
>   go n acc
>     | n > (length xs) = acc
>     | n == 1 = xs : (go (n+1) acc)
>     | n < 1 = []
>     | otherwise = (everyN n xs) : (go (n+1) acc)
>
> everyN :: Int -> [a] -> [a]
> everyN n xs =
>   case (drop (n-1) xs) of
>     y:ys -> y : (everyN n ys)
>     [] -> []
>
> How can i tell haskell compiler that a is the sub program if the same 
> as a in the main program?
>
>
> -- 
> Best Regards,
> Boon Hui
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20161114/1aa88100/attachment-0001.html>

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

Message: 3
Date: Sun, 13 Nov 2016 21:58:27 -0500
From: Chris Sasarak <csasa...@mailbox.org>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Equivalence (or not) of lists
Message-ID: <87fumuwywc....@mailbox.org>
Content-Type: text/plain


In this case it's not too bad adding parens to make:

   length' (1:2:3:[])

But in the future sometimes it can get harder, so we have a handy
function '$' which is just function application, but it has the lowest
precedence. What this means is everything on its right side is evaluated
and then applied to the function on its left. Your code would look like
this:

    length' $ 1:2:3:[]
    
In some cases this can be more readable.

Best,
Chris

Francesco Ariis writes:

> On Sat, Nov 12, 2016 at 08:20:19PM +0000, Lawrence Wickert wrote:
>> Hello all,
>> 
>> I am a rank beginner to functional languages.  Working through
>> Lipovaca's book, up to Chapter 3.
>> 
>> [...]
>>
>> *Main> length' 1:2:3:[]
>
> Hello Lawrence,
>     remember that function application has precedence over operators!
>
> So writing:
>
>     *Main> length' 1:2:3:[]
>
> is equivalent to writing
>
>     *Main> (length' 1) :2:3:[]
>
> (which is not what you want). If you add parentheses, your expression
> works again!
>
>     *Main> length' (1:2:3:[])
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

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

Reply via email to