Send Beginners mailing list submissions to
        [email protected]

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
        [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.  Is it possible to check list length at compile   time?
      (Kelong Cong)
   2. Re:  Is it possible to check list length at compile time?
      (David McBride)
   3. Re:  Is it possible to check list length at compile time?
      (Francesco Ariis)
   4. Re:  Is it possible to check list length at compile time?
      (Konstantine Rybnikov)
   5.  Have I just broken Haskell? (Mark Carter)
   6. Re:  Have I just broken Haskell? (Bob Ippolito)
   7. Re:  Is it possible to check list length at compile time?
      (Kelong Cong)


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

Message: 1
Date: Tue, 17 Mar 2015 17:26:39 +0000
From: Kelong Cong <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Is it possible to check list length at
        compile time?
Message-ID:
        <CAAuZ_wVBTen=tq03xtzvh7losvoduvale6b7nkwuu9cewbt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello,

I have a function that takes a list as its parameter. The list must always
have the same length, for example 16. Instead of producing a "Nothing" or
bottom out when an invalid list is supplied, are there ways to verify this
at compile time? If not, are there alternative data types that has this
kind of functionality?

Thanks,
Kelong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150317/99990cd3/attachment-0001.html>

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

Message: 2
Date: Tue, 17 Mar 2015 13:53:35 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Is it possible to check list length
        at compile time?
Message-ID:
        <can+tr410ytdufqx6pwb08pop8hgrkvhrwqkrdtqk58zvcs8...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

It is possible to go part of the way.  See for example, the NonEmpty type
in the semigroups package.  It is a list that always has at least one
element by restricting the operations you can do to the type without
turning it into a normal list.  You could easily adapt that solution to a
sixteen element list, but it might not be a reasonable amount of trouble to
go through.

On Tue, Mar 17, 2015 at 1:26 PM, Kelong Cong <[email protected]> wrote:

> Hello,
>
> I have a function that takes a list as its parameter. The list must always
> have the same length, for example 16. Instead of producing a "Nothing" or
> bottom out when an invalid list is supplied, are there ways to verify this
> at compile time? If not, are there alternative data types that has this
> kind of functionality?
>
> Thanks,
> Kelong
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150317/e15b3fdd/attachment-0001.html>

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

Message: 3
Date: Tue, 17 Mar 2015 19:05:04 +0100
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Is it possible to check list length
        at compile time?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, Mar 17, 2015 at 05:26:39PM +0000, Kelong Cong wrote:
> I have a function that takes a list as its parameter. The list must always
> have the same length, for example 16. Instead of producing a "Nothing" or
> bottom out when an invalid list is supplied, are there ways to verify this
> at compile time? If not, are there alternative data types that has this
> kind of functionality?

Wouldn't a gigantic 16-sized tuple solve the matter (or any datatype
with 16 accessors)?

What functions are you using on the list?


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

Message: 4
Date: Tue, 17 Mar 2015 20:35:58 +0200
From: Konstantine Rybnikov <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Is it possible to check list length
        at compile time?
Message-ID:
        <caabahfsoq6jeyiew+nqkfgms_kosze4+o6sjurft4j4kmmy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Kelong!

Check out
https://hackage.haskell.org/package/sized-vector-0.0.2.0/docs/Data-Vector-Sized.html
for a vector which has its size stored in type itself.

Cheers.

On Tue, Mar 17, 2015 at 7:26 PM, Kelong Cong <[email protected]> wrote:

> Hello,
>
> I have a function that takes a list as its parameter. The list must always
> have the same length, for example 16. Instead of producing a "Nothing" or
> bottom out when an invalid list is supplied, are there ways to verify this
> at compile time? If not, are there alternative data types that has this
> kind of functionality?
>
> Thanks,
> Kelong
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150317/a7f87dbc/attachment-0001.html>

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

Message: 5
Date: Tue, 17 Mar 2015 21:55:29 +0000
From: Mark Carter <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Have I just broken Haskell?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Persuant to my previous question, I have made some progress, but there 
is something odd going on.

Suppose we want to implement the following algorithm, which is a little 
simpler than the original problem:

The user types the name of a file as input. Haskell then puts the text 
"it works" to that file. I tried this:

import System.IO
let openFileWrite name = openFile name WriteMode
h :: IO Handle
h <- fmap openFileWrite getLine -- you need to type in a file name

This looks wrong, because h presumably needs to be a fixed Handle. Being 
an IO Handle seems to imply it is mutable. Haskell doesn't complain, though.

We also have the problem of how we are going to use hPutStr to put a 
string to the file. We can't do
     hPutStr h "it works"
because h doesn't have the right type. I tried getting around it by 
creating a function
     let put  s h = hPutStr h s
     fmap (put "it works") h
But that doesn't work, it says
    *** Exception: wow: openFile: resource busy (file is locked)

I'm guessing what I've done is create a stream OUT OF the file handle, 
rather than FOR THE file handle.

Urgh! Any ideas what the fix is?


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

Message: 6
Date: Tue, 17 Mar 2015 15:16:25 -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] Have I just broken Haskell?
Message-ID:
        <cacwmpm9nejkxs61eoxmfuvbxm+zykevl0ptms3z1f_ogh_o...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Mar 17, 2015 at 2:55 PM, Mark Carter <[email protected]> wrote:

> Persuant to my previous question, I have made some progress, but there is
> something odd going on.
>
> Suppose we want to implement the following algorithm, which is a little
> simpler than the original problem:
>
> The user types the name of a file as input. Haskell then puts the text "it
> works" to that file. I tried this:
>
> import System.IO
> let openFileWrite name = openFile name WriteMode
> h :: IO Handle
> h <- fmap openFileWrite getLine -- you need to type in a file name
>
> This looks wrong, because h presumably needs to be a fixed Handle. Being
> an IO Handle seems to imply it is mutable. Haskell doesn't complain, though.
>

This is wrong because the type of `h` should be Handle, not IO Handle.
`fmap` is not the correct function to use here, you use `fmap` to lift a
pure function into some Functor. What you need to do is sequence these two
IO actions, like this:

name <- getLine
h <- openFileWrite name

Which is equivalent to this:

h <- getLine >>= openFileWrite

or this (`=<<` is just a flipped `>>=` operator):

h <- openFileWrite =<< getLine

-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150317/bede3c20/attachment-0001.html>

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

Message: 7
Date: Tue, 17 Mar 2015 22:50:19 +0000
From: Kelong Cong <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Is it possible to check list length
        at compile time?
Message-ID:
        <CAAuZ_wWbCR2PH8x9roiJKR9-MeubOpOiKqHNUt=y27dwe_k...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks for the suggestion guys, I think the sized vector is just what I
needed!

I know about tuples but I can't use the usual list functions like map,
splitAt etc, also there is no need to have more than one data type.

On 17 March 2015 at 18:35, Konstantine Rybnikov <[email protected]> wrote:

> Hi Kelong!
>
> Check out
> https://hackage.haskell.org/package/sized-vector-0.0.2.0/docs/Data-Vector-Sized.html
> for a vector which has its size stored in type itself.
>
> Cheers.
>
> On Tue, Mar 17, 2015 at 7:26 PM, Kelong Cong <[email protected]> wrote:
>
>> Hello,
>>
>> I have a function that takes a list as its parameter. The list must
>> always have the same length, for example 16. Instead of producing a
>> "Nothing" or bottom out when an invalid list is supplied, are there ways to
>> verify this at compile time? If not, are there alternative data types that
>> has this kind of functionality?
>>
>> Thanks,
>> Kelong
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150317/16e7abc6/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 81, Issue 48
*****************************************

Reply via email to