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:  Haskeline and forkIO (Jeff C. Britton)
   2.  Check constructor's field numeric value at       compile time
      (Dmitriy Matrosov)
   3. Re:  Check constructor's field numeric value at compile time
      (Alexandre Lucchesi)
   4. Re:  Check constructor's field numeric value at compile time
      (Julian Birch)
   5. Re:  Check constructor's field numeric value at compile time
      (Kim-Ee Yeoh)
   6. Re:  Check constructor's field numeric value at compile time
      (Alexandre Lucchesi)
   7. Re:  Check constructor's field numeric value at compile time
      (Brandon Allbery)


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

Message: 1
Date: Tue, 2 Sep 2014 18:19:23 +0000
From: "Jeff C. Britton" <[email protected]>
To: Peter Jones <[email protected]>, The Haskell-Beginners Mailing List
        - Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Subject: Re: [Haskell-beginners] Haskeline and forkIO
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Thanks Peter,

That suggestion works.
I will have to continue learning more about Monads.

--Jeff


-----Original Message-----
From: Beginners [mailto:[email protected]] On Behalf Of Peter Jones
Sent: Thursday, August 28, 2014 7:11 AM
To: [email protected]
Subject: Re: [Haskell-beginners] Haskeline and forkIO

"Jeff C. Britton" <[email protected]> writes:
> loop :: InputT IO ()
> loop = do
>     maybeLine <- getInputLine "Enter a file to compress> "
>     case maybeLine of
>       Nothing -> return ()      -- user entered EOF
>       Just "" -> return ()      -- treat no name as "want to quit" 
>       Just path -> do
>             return (runWorker path)
>             loop

The other issue you're having is because `runWorker path` is an `IO ()` value 
but at the point where you use it in the code the type system wants an `InputT 
IO ()`.  To try to satisfy the type system you used `return` to build a `InputT 
IO (IO ())` value, but that doesn't actually work (as you've noticed).  Since 
`InputT` is a transformer you have an extra layer to work through and so need 
to *lift* your `IO ()` value into the `InputT IO` layer.  Try this:

    -- Add this import
    import Control.Monad.IO.Class
    
    loop :: InputT IO ()
    loop = do
        maybeLine <- getInputLine "Enter a file to compress> "
        case maybeLine of
          Nothing -> return ()      -- user entered EOF
          Just "" -> return ()      -- treat no name as "want to quit" 
          Just path -> do
                liftIO (runWorker path)
                loop
    

You can think of `liftIO` as having this signature (in this context):

    liftIO :: IO () -> InputT IO ()
    
--
Peter Jones, Founder, Devalot.com
Defending the honor of good code

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


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

Message: 2
Date: Tue, 02 Sep 2014 23:32:35 +0400
From: Dmitriy Matrosov <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Check constructor's field numeric value
        at      compile time
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi.

I have a type

data Interval   = Seconds Float
                | MicroSeconds Int

The Float field of data constructor Seconds should be >= 1, and Int 
field of constructor MicroSeconds should be in the range from 0 to 1000000.

How can i write this constraints so they're checked at compile time, not 
at runtime?

--
     Dmitriy Matrosov


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

Message: 3
Date: Tue, 2 Sep 2014 17:58:24 -0300
From: Alexandre Lucchesi <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Check constructor's field numeric
        value at compile time
Message-ID:
        <cagqbpevraeccsseqqw1m4cyrv9o2j+g0bxcxzfstsj7xsqm...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You can't do that within the data type declaration.

In order to add such constraints you should define "constructor functions"
and apply the validation there, i.e.:

newSecondsInterval :: Float -> Maybe Interval
newSecondsInterval n
  | n >= 1     = Just $ Seconds n
  | otherwise = Nothing

Note that the "Maybe" type is only a way to handle the case where the
supplied value is invalid. Also, in order to provide encapsulation and
ensure no one is going to create a new "Interval" by using "Seconds" and
"MicroSeconds", you should hide these value constructors in the export list
of your module.


On Tue, Sep 2, 2014 at 4:32 PM, Dmitriy Matrosov <[email protected]> wrote:

> Hi.
>
> I have a type
>
> data Interval   = Seconds Float
>                 | MicroSeconds Int
>
> The Float field of data constructor Seconds should be >= 1, and Int field
> of constructor MicroSeconds should be in the range from 0 to 1000000.
>
> How can i write this constraints so they're checked at compile time, not
> at runtime?
>
> --
>     Dmitriy Matrosov
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
alexandre lucchesi

*Perfection is achieved, not when there is nothing more to add, but when
there is nothing left to take away!*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140902/d1f58cbf/attachment-0001.html>

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

Message: 4
Date: Tue, 2 Sep 2014 23:02:48 +0100
From: Julian Birch <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Check constructor's field numeric
        value at compile time
Message-ID:
        <cab0tuzcbwmy5xpv4uqqszuzqgtplq6ut8azdca38hzbimjm...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Also, if you want your mind blown, check out Idris.

On Tuesday, September 2, 2014, Alexandre Lucchesi <
[email protected]> wrote:

> You can't do that within the data type declaration.
>
> In order to add such constraints you should define "constructor functions"
> and apply the validation there, i.e.:
>
> newSecondsInterval :: Float -> Maybe Interval
> newSecondsInterval n
>   | n >= 1     = Just $ Seconds n
>   | otherwise = Nothing
>
> Note that the "Maybe" type is only a way to handle the case where the
> supplied value is invalid. Also, in order to provide encapsulation and
> ensure no one is going to create a new "Interval" by using "Seconds" and
> "MicroSeconds", you should hide these value constructors in the export list
> of your module.
>
>
> On Tue, Sep 2, 2014 at 4:32 PM, Dmitriy Matrosov <[email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote:
>
>> Hi.
>>
>> I have a type
>>
>> data Interval   = Seconds Float
>>                 | MicroSeconds Int
>>
>> The Float field of data constructor Seconds should be >= 1, and Int field
>> of constructor MicroSeconds should be in the range from 0 to 1000000.
>>
>> How can i write this constraints so they're checked at compile time, not
>> at runtime?
>>
>> --
>>     Dmitriy Matrosov
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> <javascript:_e(%7B%7D,'cvml','[email protected]');>
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
>
> --
> alexandre lucchesi
>
> *Perfection is achieved, not when there is nothing more to add, but when
> there is nothing left to take away!*
>


-- 
Sent from an iPhone, please excuse brevity and typos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140902/bfae26be/attachment-0001.html>

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

Message: 5
Date: Wed, 3 Sep 2014 10:04:10 +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] Check constructor's field numeric
        value at compile time
Message-ID:
        <CAPY+ZdRcp1=_GDXrGOt5OtkwD-1ndk+=nsyh82laa88kamp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Wed, Sep 3, 2014 at 3:58 AM, Alexandre Lucchesi <
[email protected]> wrote:

> In order to add such constraints you should define "constructor functions"
> and apply the validation there, i.e.:


To OP: Yes, the searchable term is "smart constructors". However, it has
been used at least once on this list to mean something different, so look
out.

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

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

Message: 6
Date: Wed, 3 Sep 2014 00:07:10 -0300
From: Alexandre Lucchesi <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Check constructor's field numeric
        value at compile time
Message-ID:
        <CAGqBpeUaPeUPYWKjhjRqdHYEnt-s=48uzgqTnVpqN=smhqc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hmm.. Nice to know about that!

Thank you. :)


On Wed, Sep 3, 2014 at 12:04 AM, Kim-Ee Yeoh <[email protected]> wrote:

>
> On Wed, Sep 3, 2014 at 3:58 AM, Alexandre Lucchesi <
> [email protected]> wrote:
>
>> In order to add such constraints you should define "constructor
>> functions" and apply the validation there, i.e.:
>
>
> To OP: Yes, the searchable term is "smart constructors". However, it has
> been used at least once on this list to mean something different, so look
> out.
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
alexandre lucchesi

*Perfection is achieved, not when there is nothing more to add, but when
there is nothing left to take away!*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140903/a15f537c/attachment-0001.html>

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

Message: 7
Date: Tue, 2 Sep 2014 23:07:31 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Check constructor's field numeric
        value at compile time
Message-ID:
        <cakfcl4we5vdavt0fjkxlpsytuq-vw4-jw-nf7jjvbgyy1to...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Sep 2, 2014 at 11:04 PM, Kim-Ee Yeoh <[email protected]> wrote:
>
> On Wed, Sep 3, 2014 at 3:58 AM, Alexandre Lucchesi <
> [email protected]> wrote:
>
>> In order to add such constraints you should define "constructor
>> functions" and apply the validation there, i.e.:
>
>
> To OP: Yes, the searchable term is "smart constructors". However, it has
> been used at least once on this list to mean something different, so look
> out.
>

Also note that this will not actually check at compile time; to do that you
need type level stuff that ghc is still finding its way through.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140902/87d73d10/attachment.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 75, Issue 2
****************************************

Reply via email to