Send Beginners mailing list submissions to
        beginners@haskell.org

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
        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. Re:  User-defined polymorphic data type: heterogeneous list?
      (Chadda? Fouch?)
   2.  function defenition. Do I understand it right? (Roelof Wobben)
   3. Re:  function defenition. Do I understand it      right?
      (David McBride)
   4. Re:  function defenition. Do I understand it right?
      (Roelof Wobben)
   5. Re:  function defenition. Do I understand it      right? (Jack Henahan)
   6. Re:  Working out the types (Patrick LeBoutillier)
   7. Re:  function defenition. Do I understand it right?
      (Roelof Wobben)


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

Message: 1
Date: Mon, 11 Jul 2011 12:21:14 +0200
From: Chadda? Fouch? <chaddai.fou...@gmail.com>
Subject: Re: [Haskell-beginners] User-defined polymorphic data type:
        heterogeneous list?
To: Arlen Cuss <cel...@sairyx.org>
Cc: Haskell Beginners <beginners@haskell.org>
Message-ID:
        <CANfjZRZSzoxns8VytsQx3JOAZTc2YJLh7=vz9yvtkk8hf4s...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Mon, Jul 11, 2011 at 8:21 AM, Arlen Cuss <cel...@sairyx.org> wrote:
> Hi Christopher,
>
>> As my first stab at it, it seemed like I should be able to create my own
>> heterogeneous "list" data type -- i.e., a "list" data type that can
>> contain elements of different types. (like, [3,'a',True], for example)
>
> One problem I can see would be dealing with the contents of such a list.
> Imagine you have a list with many different types in it. Would every
> type appear in the type of the list? If so, that would have to be a
> consideration before you even get to the "=" sign in your data type
> definition. If not, whence do they come?

That approach can be found in the HList library where indeed the
heterogeneous list at the data level is echoed by an heterogeneous
list at the type level, the basic blocks are :

> data HNil = HNil
> data HCons e l = HCons e l

but with just that you would have no guarantee that the "l" from HCons
was HNil or HCons so you add a typeclass :

> class HList l
> instance HList HNil
> instance (HList l) => HList (HCons e l)

and you don't export the data constructors but smart constructors instead :

> hNil :: HNil
> hNil = HNil
>
> hCons :: (HList l) => e -> l -> HCons e l
> hCons x xs = HCons x xs

And thus you have an heterogeneous list which you can manipulate
usefully, though HList add plenty of stuff to allow cool tricks.

-- 
Jeda?



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

Message: 2
Date: Mon, 11 Jul 2011 14:48:26 +0000
From: Roelof Wobben <rwob...@hotmail.com>
Subject: [Haskell-beginners] function defenition. Do I understand it
        right?
To: <beginners@haskell.org>
Message-ID: <snt118-w41b1e852b05037d517f001ae...@phx.gbl>
Content-Type: text/plain; charset="iso-8859-1"


Hello, 

I have made a exercise where I must split a even list.
The answer is :

halve xs = (take n xs  drop n xs) 
     where n = length xs 'div' 2 

Now I want to change it so i can split even and not even list,.
I thought this can be the answer 

halve xs = 
         lenght xs 'mod' 2 = 0  : (take n  xs   drop n xs) 
         otherwise :  (take n+1 xs  drop n+1 xs) 
         where 
             n = length xs 'div' 2 


Can this be working ?
I did not check this on GCHI because Im  re - installing my OS.

Regards. 

Roelof

                                          
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110711/d5ab7dc4/attachment-0001.htm>

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

Message: 3
Date: Mon, 11 Jul 2011 11:44:28 -0400
From: David McBride <dmcbr...@neondsl.com>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: Roelof Wobben <rwob...@hotmail.com>
Cc: beginners@haskell.org
Message-ID:
        <can+tr40drku8gttfon-63z87vmdmovmq-fhc4vwsqpjdgye...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

For simple snippets like this, you can go to
http://codepad.org/ddySVOPr and run your code to see if it works.

And your first version (once corrected for syntax) works on any list
length except for empty lists.

On Mon, Jul 11, 2011 at 10:48 AM, Roelof Wobben <rwob...@hotmail.com> wrote:
> Hello,
>
> I have made a exercise where I must split a even list.
> The answer is :
>
> halve xs = (take n xs? drop n xs)
> ???? where n = length xs 'div' 2
>
> Now I want to change it so i can split even and not even list,.
> I thought this can be the answer
>
> halve xs =
> ???????? lenght xs 'mod' 2 = 0? : (take n? xs?? drop n xs)
> ???????? otherwise :? (take n+1 xs? drop n+1 xs)
> ???????? where
> ???????????? n = length xs 'div' 2
>
>
> Can this be working ?
> I did not check this on GCHI because Im? re - installing my OS.
>
> Regards.
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



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

Message: 4
Date: Mon, 11 Jul 2011 19:51:15 +0000
From: Roelof Wobben <rwob...@hotmail.com>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it right?
To: <beginners@haskell.org>
Message-ID: <snt118-w770530ef4ca12220fc33eae...@phx.gbl>
Content-Type: text/plain; charset="iso-8859-1"


Hello, 

Thanks for the tip.
Im stuck now.

I have this : 

halve (xs) | length xs'mod'2 == 0   = (take n xs drop n xs)
           | otherwise = (take n+1 xs  drop n+1 xs
           where n= lenght xs'div'2 


main = do
  putStrLn $ show $ halve [1,2,3,4]
  putStrLn $ show $ halve [1,2,3]

But now I get this message :

ERROR line 3 - Syntax error in expression (unexpected keyword "where")

Appearently I can't use where here.

How can I solve this ?

Roelof



> Date: Mon, 11 Jul 2011 11:44:28 -0400
> Subject: Re: [Haskell-beginners] function defenition. Do I understand it 
> right?
> From: dmcbr...@neondsl.com
> To: rwob...@hotmail.com
> CC: beginners@haskell.org
> 
> For simple snippets like this, you can go to
> http://codepad.org/ddySVOPr and run your code to see if it works.
> 
> And your first version (once corrected for syntax) works on any list
> length except for empty lists.
> 
> On Mon, Jul 11, 2011 at 10:48 AM, Roelof Wobben <rwob...@hotmail.com> wrote:
> > Hello,
> >
> > I have made a exercise where I must split a even list.
> > The answer is :
> >
> > halve xs = (take n xs  drop n xs)
> >      where n = length xs 'div' 2
> >
> > Now I want to change it so i can split even and not even list,.
> > I thought this can be the answer
> >
> > halve xs =
> >          lenght xs 'mod' 2 = 0  : (take n  xs   drop n xs)
> >          otherwise :  (take n+1 xs  drop n+1 xs)
> >          where
> >              n = length xs 'div' 2
> >
> >
> > Can this be working ?
> > I did not check this on GCHI because Im  re - installing my OS.
> >
> > Regards.
> >
> > Roelof
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >
                                          
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110711/b8bece7a/attachment-0001.htm>

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

Message: 5
Date: Mon, 11 Jul 2011 15:56:23 -0400
From: Jack Henahan <jhena...@uvm.edu>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: Haskell Beginners <beginners@haskell.org>
Message-ID: <4cd49572-77fa-4517-96d2-76276b5df...@uvm.edu>
Content-Type: text/plain; charset=iso-8859-1

Forgot to CC the list.

Begin forwarded message:

> From: Jack Henahan <jhena...@uvm.edu>
> Subject: Re: [Haskell-beginners] function defenition. Do I understand it 
> right?
> Date: July 11, 2011 3:55:13 PM EDT
> To: Roelof Wobben <rwob...@hotmail.com>
> 
> You're overcomplicating things. Look at splitAt from Data.List:
> 
> http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Data-List.html#v%3AsplitAt
> 
> On Jul 11, 2011, at 3:51 PM, Roelof Wobben wrote:
> 
>> Hello, 
>> 
>> Thanks for the tip.
>> Im stuck now.
>> 
>> I have this : 
>> 
>> halve (xs) | length xs'mod'2 == 0   = (take n xs drop n xs)
>>           | otherwise = (take n+1 xs  drop n+1 xs
>>           where n= lenght xs'div'2 
>> 
>> 
>> main = do
>>  putStrLn $ show $ halve [1,2,3,4]
>>  putStrLn $ show $ halve [1,2,3]
>> 
>> But now I get this message :
>> 
>> ERROR line 3 - Syntax error in expression (unexpected keyword "where")
>> 
>> Appearently I can't use where here.
>> 
>> How can I solve this ?
>> 
>> Roelof
>> 
>> 
>> 
>>> Date: Mon, 11 Jul 2011 11:44:28 -0400
>>> Subject: Re: [Haskell-beginners] function defenition. Do I understand it 
>>> right?
>>> From: dmcbr...@neondsl.com
>>> To: rwob...@hotmail.com
>>> CC: beginners@haskell.org
>>> 
>>> For simple snippets like this, you can go to
>>> http://codepad.org/ddySVOPr and run your code to see if it works.
>>> 
>>> And your first version (once corrected for syntax) works on any list
>>> length except for empty lists.
>>> 
>>> On Mon, Jul 11, 2011 at 10:48 AM, Roelof Wobben <rwob...@hotmail.com> wrote:
>>>> Hello,
>>>> 
>>>> I have made a exercise where I must split a even list.
>>>> The answer is :
>>>> 
>>>> halve xs = (take n xs  drop n xs)
>>>>     where n = length xs 'div' 2
>>>> 
>>>> Now I want to change it so i can split even and not even list,.
>>>> I thought this can be the answer
>>>> 
>>>> halve xs =
>>>>         lenght xs 'mod' 2 = 0  : (take n  xs   drop n xs)
>>>>         otherwise :  (take n+1 xs  drop n+1 xs)
>>>>         where
>>>>             n = length xs 'div' 2
>>>> 
>>>> 
>>>> Can this be working ?
>>>> I did not check this on GCHI because Im  re - installing my OS.
>>>> 
>>>> Regards.
>>>> 
>>>> Roelof
>>>> 
>>>> 
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners@haskell.org
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>> 
>>>> 
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
> 




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

Message: 6
Date: Mon, 11 Jul 2011 16:24:56 -0400
From: Patrick LeBoutillier <patrick.leboutill...@gmail.com>
Subject: Re: [Haskell-beginners] Working out the types
To: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Cc: beginners@haskell.org
Message-ID:
        <cajcqsbhovbjw95kqqvweq0fqdcfpe0kokpenztbaptjphjw...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi Daniel,

I took the code that accompanies the paper and I'm trying to use it
but I can't figure out how to get started.
I have the following code but it is not giving me the expected result:

import TypingHaskellInHaskell

mapt = "map" :>: Forall [Star, Star]
             ([] :=>
              ((TGen 0 `fn` TGen 1) `fn` TAp tList (TGen 0) `fn` TAp
tList (TGen 1)))

idt = "id" :>: Forall [Star]
             ([] :=>
              (TGen 0 `fn` TGen 0))

exprt = Ap (Const mapt) (Const idt)

test = runTI $ tiExpr initialEnv [] exprt


When I execute the test function above in ghci I get:

([],TVar (Tyvar "v3" Star)).

I was expecting someting like below for the type part:

TAp tList (TGen 0) `fn` TAp tList (TGen 0)


What I want is the library to compute for me the type of "map id".
What is the proper way to achieve this?



Thanks a lot,

Patrick


On Wed, Jul 6, 2011 at 8:19 AM, Patrick LeBoutillier
<patrick.leboutill...@gmail.com> wrote:
> Daniel,
>
> The paper you recommend seems like very interesting stuff. ?I will
> definitely look at it closer.
>
>
> Thanks a lot,
>
> Patrick
>
>
> On Tue, Jul 5, 2011 at 3:24 PM, Daniel Fischer
> <daniel.is.fisc...@googlemail.com> wrote:
>> On Tuesday 05 July 2011, 19:55:43, Patrick LeBoutillier wrote:
>>> Hi all,
>>
>>> Here's my question: Does ghci have a verbose mode or something where
>>> is can show you step by step how the types
>>> are worked out?
>>
>> No. You can use it to get the types of subexpressions, though, and work
>> towards the complete expression from that:
>>
>> Prelude> :t (:)
>> (:) :: a -> [a] -> [a]
>> Prelude> :t (. (:))
>> (. (:)) :: (([a] -> [a]) -> c) -> a -> c
>> Prelude> :t (map . (:))
>> (map . (:)) :: a -> [[a]] -> [[a]]
>>
>> which gives you smaller gaps to fill in.
>>
>>> If not is there a hackage (or any other kind of)
>>> package that can do that?
>>
>> I'm not aware of any, but there might be.
>>
>>>
>>> a lot, so I was wondering if such a program existed that could do it
>>> automatically.
>>
>> Automatic type checkers do exist (every compiler/interpreter needs one),
>> but I don't think they have been written with the ability to output not
>> only the result but also the derivation.
>>
>> For someone familiar with a particular type checker, it probably wouldn't
>> be hard to add that feature, but if it's a complicated beast like GHC's
>> type checker, becoming familiar with it would probably be a big
>> undertaking.
>>
>> Writing your own much-reduced (able to parse and typecheck only a very
>> restricted subset of the language) might be easier, but probably working
>> from Mark P. Jones' "Typing Haskell in Haskell"
>> http://web.cecs.pdx.edu/~mpj/thih/
>> would be better than starting from scratch (it's somewhat oldish, so it
>> certainly doesn't cope with recent GHC extensions, but for everyday run-of-
>> the-mill problems, it should be working with only minor modifications).
>>
>>
>
>
>
> --
> =====================
> Patrick LeBoutillier
> Rosem?re, Qu?bec, Canada
>



-- 
=====================
Patrick LeBoutillier
Rosem?re, Qu?bec, Canada



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

Message: 7
Date: Mon, 11 Jul 2011 21:13:58 +0000
From: Roelof Wobben <rwob...@hotmail.com>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it right?
To: <beginners@haskell.org>
Message-ID: <snt118-w27ea24e29f155ffa713346ae...@phx.gbl>
Content-Type: text/plain; charset="iso-8859-1"


Hello, 

 

I had a look at it but I don't think it will solve my problem.

What I try to achieve is this:

 

[1,2,3,4] will be [1,2] [3,4]

[1,2,3,4,5] will be [1,2,3] [3,4,5]

 

So the halfs have to be the same lenght.

 

So I use : 

 

length xs'div' 2 to figure out where the middle is.

lenght xs'mod'2 to look if it's a even or not even list.

 

So I can use splitat but then the lists will not be the same length if it's a 
not even list.

 

Roelof



----------------------------------------
> Subject: Re: [Haskell-beginners] function defenition. Do I understand it 
> right?
> From: jhena...@uvm.edu
> Date: Mon, 11 Jul 2011 15:55:13 -0400
> To: rwob...@hotmail.com
>
> You're overcomplicating things. Look at splitAt from Data.List:
>
> http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Data-List.html#v%3AsplitAt
>
> On Jul 11, 2011, at 3:51 PM, Roelof Wobben wrote:
>
> > Hello,
> >
> > Thanks for the tip.
> > Im stuck now.
> >
> > I have this :
> >
> > halve (xs) | length xs'mod'2 == 0 = (take n xs drop n xs)
> > | otherwise = (take n+1 xs drop n+1 xs
> > where n= lenght xs'div'2
> >
> >
> > main = do
> > putStrLn $ show $ halve [1,2,3,4]
> > putStrLn $ show $ halve [1,2,3]
> >
> > But now I get this message :
> >
> > ERROR line 3 - Syntax error in expression (unexpected keyword "where")
> >
> > Appearently I can't use where here.
> >
> > How can I solve this ?
> >
> > Roelof
> >
> >
> >
> > > Date: Mon, 11 Jul 2011 11:44:28 -0400
> > > Subject: Re: [Haskell-beginners] function defenition. Do I understand it 
> > > right?
> > > From: dmcbr...@neondsl.com
> > > To: rwob...@hotmail.com
> > > CC: beginners@haskell.org
> > >
> > > For simple snippets like this, you can go to
> > > http://codepad.org/ddySVOPr and run your code to see if it works.
> > >
> > > And your first version (once corrected for syntax) works on any list
> > > length except for empty lists.
> > >
> > > On Mon, Jul 11, 2011 at 10:48 AM, Roelof Wobben <rwob...@hotmail.com> 
> > > wrote:
> > > > Hello,
> > > >
> > > > I have made a exercise where I must split a even list.
> > > > The answer is :
> > > >
> > > > halve xs = (take n xs drop n xs)
> > > > where n = length xs 'div' 2
> > > >
> > > > Now I want to change it so i can split even and not even list,.
> > > > I thought this can be the answer
> > > >
> > > > halve xs =
> > > > lenght xs 'mod' 2 = 0 : (take n xs drop n xs)
> > > > otherwise : (take n+1 xs drop n+1 xs)
> > > > where
> > > > n = length xs 'div' 2
> > > >
> > > >
> > > > Can this be working ?
> > > > I did not check this on GCHI because Im re - installing my OS.
> > > >
> > > > Regards.
> > > >
> > > > Roelof
> > > >
> > > >
> > > > _______________________________________________
> > > > Beginners mailing list
> > > > Beginners@haskell.org
> > > > http://www.haskell.org/mailman/listinfo/beginners
> > > >
> > > >
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
>                                         


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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 37, Issue 18
*****************************************

Reply via email to