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. Re:  understanding function signature alignement
      (simkest...@gmail.com)
   2.  How to write the FromJSON instance for CUid
      (PICCA Frederic-Emmanuel)
   3. Re:  How to write the FromJSON instance for CUid (David McBride)
   4. Re:  How to write the FromJSON instance for CUid (David McBride)
   5. Re:  How to write the FromJSON instance for CUid
      (PICCA Frederic-Emmanuel)
   6. Re:  understanding function signature alignement
      (Theodore Lief Gannon)


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

Message: 1
Date: Thu, 9 Aug 2018 16:22:17 +0200
From: "simkest...@gmail.com" <simkest...@gmail.com>
To: Hask begginers <beginners@haskell.org>
Subject: Re: [Haskell-beginners] understanding function signature
        alignement
Message-ID:
        <CAJqT=ykhfzvprb51v1+fmdevu5plypspt6_znax1fqdaplu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

>
> Thanks, it is still a bit fuzzy to me ...


I understand what you did  but what confuses me is that when i look at
function with signature like

f :: Monad m => c -> m d

I always think that return type is somehow restricted in comparison to
input because it demands that output type is wraped inside something (monad
in this case).

For such signature to fit id signature (a -> a) ,  c type shoud be also
wraped inside monad but it is not case here...

Anyhow, I still have to figure it out

thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180809/a62de9d9/attachment-0001.html>

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

Message: 2
Date: Thu, 9 Aug 2018 15:37:51 +0000
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.pi...@synchrotron-soleil.fr>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <beginners@haskell.org>
Subject: [Haskell-beginners] How to write the FromJSON instance for
        CUid
Message-ID:
        
<a2a20ec3b8560d408356cac2fc148e530156b3f...@sun-dag3.synchrotron-soleil.fr>
        
Content-Type: text/plain; charset="us-ascii"

Hello, I try to write the instance for the CUid[1] type
But I do not know what to do.

instance FromJSON CUid where
    parseJSON = ...
    {-# INLINE parseJSON #-}

Thansk for your help


[1] 
https://hackage.haskell.org/package/base-4.11.1.0/docs/System-Posix-Types.html#t:CUid

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

Message: 3
Date: Thu, 9 Aug 2018 13:06:40 -0400
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] How to write the FromJSON instance
        for CUid
Message-ID:
        <CAN+Tr41yMP4HKkszV_-6NmA-ikn-B5+ssUS=yrogs_ayyud...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You have to worry about json having a floating point number or an integer
that is too large to be represented in a Word32, although you could also
just let it overflow if you don't care too much.  There's probably an
easier way to do this, but this is what I came up with.

instance FromJSON CUid where
  parseJSON (Number n) = do

    case floatingOrInteger n of
      Right i | inrange i -> return . CUid . fromIntegral $ i

     -- not an integer, or not in range
      _ -> mempty

    where
      inrange :: Integer -> Bool
      inrange i = fromIntegral i >= (minBound @Word32) &&
                    fromIntegral i <= (maxBound @Word32)

  -- not a number
  parseJSON _ = mempty


On Thu, Aug 9, 2018 at 11:37 AM, PICCA Frederic-Emmanuel <
frederic-emmanuel.pi...@synchrotron-soleil.fr> wrote:

> Hello, I try to write the instance for the CUid[1] type
> But I do not know what to do.
>
> instance FromJSON CUid where
>     parseJSON = ...
>     {-# INLINE parseJSON #-}
>
> Thansk for your help
>
>
> [1] https://hackage.haskell.org/package/base-4.11.1.0/docs/
> System-Posix-Types.html#t:CUid
> _______________________________________________
> 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/20180809/7200ab11/attachment-0001.html>

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

Message: 4
Date: Thu, 9 Aug 2018 13:10:48 -0400
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] How to write the FromJSON instance
        for CUid
Message-ID:
        <can+tr43vkz33zgzcb79zngfxh_b-q9_3h5o4eb1rqmxkhf5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Sorry I really should've tested my code before I hit send.

instance FromJSON CUid where
  parseJSON (Number n) = do
    case floatingOrInteger n of
      Right i | inrange i -> return . CUid . fromIntegral $ i
      _ -> mempty

    where
      inrange :: Integer -> Bool
      inrange i = i >= fromIntegral (minBound @Word32) &&
                  i <= fromIntegral (maxBound @Word32)

  parseJSON _ = mempty


On Thu, Aug 9, 2018 at 1:06 PM, David McBride <toa...@gmail.com> wrote:

> You have to worry about json having a floating point number or an integer
> that is too large to be represented in a Word32, although you could also
> just let it overflow if you don't care too much.  There's probably an
> easier way to do this, but this is what I came up with.
>
> instance FromJSON CUid where
>   parseJSON (Number n) = do
>
>     case floatingOrInteger n of
>       Right i | inrange i -> return . CUid . fromIntegral $ i
>
>      -- not an integer, or not in range
>       _ -> mempty
>
>     where
>       inrange :: Integer -> Bool
>       inrange i = fromIntegral i >= (minBound @Word32) &&
>                     fromIntegral i <= (maxBound @Word32)
>
>   -- not a number
>   parseJSON _ = mempty
>
>
> On Thu, Aug 9, 2018 at 11:37 AM, PICCA Frederic-Emmanuel <
> frederic-emmanuel.pi...@synchrotron-soleil.fr> wrote:
>
>> Hello, I try to write the instance for the CUid[1] type
>> But I do not know what to do.
>>
>> instance FromJSON CUid where
>>     parseJSON = ...
>>     {-# INLINE parseJSON #-}
>>
>> Thansk for your help
>>
>>
>> [1] https://hackage.haskell.org/package/base-4.11.1.0/docs/Syste
>> m-Posix-Types.html#t:CUid
>> _______________________________________________
>> 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/20180809/98f28d44/attachment-0001.html>

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

Message: 5
Date: Fri, 10 Aug 2018 08:05:21 +0000
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.pi...@synchrotron-soleil.fr>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <beginners@haskell.org>
Subject: Re: [Haskell-beginners] How to write the FromJSON instance
        for CUid
Message-ID:
        
<a2a20ec3b8560d408356cac2fc148e530156b40...@sun-dag3.synchrotron-soleil.fr>
        
Content-Type: text/plain; charset="us-ascii"

Hello, and thanks for the reply

What about this 

instance FromJSON CGid where
    parseJSON x = CGid <$> (parseJSON x :: Parser Word32)
    {-# INLINE parseJSON #-}


Do you think that it deal with all the problem you are trying to prevent ?


Cheers

Fred

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

Message: 6
Date: Fri, 10 Aug 2018 03:05:44 -0700
From: Theodore Lief Gannon <tan...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] understanding function signature
        alignement
Message-ID:
        <CAJoPsuD2JyuixNpCQh4tWdL1C8GcOk3pYm_P_bUN6D+2W=x...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You're right that the return type is more restricted than the argument, but
it's in an *absolute* sense, not a relative one. It's not possible to relax
`m d` to make it the same type as `c`, but it IS possible to constrain `c`
to be the same as `m d`! And that's how `id` works here: the input in this
case is known to be the same type as the output. You need something wrapped
in a monad, and you already have that, so you just use it as-is.

On Thu, Aug 9, 2018, 7:22 AM simkest...@gmail.com <simkest...@gmail.com>
wrote:

> Thanks, it is still a bit fuzzy to me ...
>
>
> I understand what you did  but what confuses me is that when i look at
> function with signature like
>
> f :: Monad m => c -> m d
>
> I always think that return type is somehow restricted in comparison to
> input because it demands that output type is wraped inside something (monad
> in this case).
>
> For such signature to fit id signature (a -> a) ,  c type shoud be also
> wraped inside monad but it is not case here...
>
> Anyhow, I still have to figure it out
>
> thanks
> _______________________________________________
> 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/20180810/484a8744/attachment.html>

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

Subject: Digest Footer

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


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

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

Reply via email to