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.  Need help to write join on my Temporals (martin)
   2. Re:  Why does QuickCheck insist on this class constraint? (martin)
   3. Re:  Why does QuickCheck insist on this class     constraint?
      (Andres L?h)
   4. Re:  Debugging in Haskell (emacstheviking)
   5.  Managing boilerplate code in QuickCheck  properties...
      (Stuart Hungerford)


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

Message: 1
Date: Fri, 10 Apr 2015 19:02:13 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Need help to write join on my Temporals
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

Hello all,

I have these Types

type Time = Integer
data Change a = Chg {
            ct :: Time, -- "change time"
            cv :: a     -- "change value"
        } deriving (Eq,Show)

data Temporal a = Temporal {
    td :: a,         -- "temporal default"
    tc :: [Change a] -- "temporal changes"
} deriving (Eq, Show)

And I am trying to make Temporal a Monad by implementing join. My first Attempt 
was awfully verbose. It was also faulty,
which was revealed by this QuickQueck (I am happy with my implementation of <*>)

prop_tJoin tpr1 tpr2 = let f  = (*)
                           y1 =  f <$> tpr1 <*>  tpr2
                           y2 = (f <$> tpr1) `ap` tpr2
                       in y1 == y2


While I understand why my first implementatin was faulty, I fail to come up 
with anything remotely readable. I don't
understand why I am having such difficulties, let alone solve them. I feel I am 
approaching this from the wrong angle.

Any advice would be very much appreciated.


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

Message: 2
Date: Fri, 10 Apr 2015 19:25:04 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Why does QuickCheck insist on this
        class constraint?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252

Am 04/01/2015 um 10:43 PM schrieb Chadda? Fouch?:
> Why are you putting those type signatures everywhere ? Won't your code 
> compile without them ? It seems to me that
> absent a strange Change type, all those things can be inferred... Are you 
> doing this as an exercise or because you
> think it is more readable ?

I had put them there, because I thought QuickCheck needs them. But you're right 
they are not needed and then my question
becomes a non-issue.


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

Message: 3
Date: Fri, 10 Apr 2015 19:51:23 +0200
From: Andres L?h <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Why does QuickCheck insist on this
        class   constraint?
Message-ID:
        <caljd_v4svtcjv8toedgy4irglguwi3yu9nhv2lazo1+enju...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi.

To answer your original question anyway:

In Haskell 2010, all type variables that appear in any type annotation
are implicitly quantified. They're not "scoped". So e.g. here:

instance (Arbitrary a, Eq a) => Arbitrary (Temporal a)
        where
            arbitrary = do
                d  <- arbitrary
                (CList cs) <- arbitrary :: (Arbitrary a, Eq a) => Gen
(CList a) -- <===
                return (Temporal d cs)

if you say just "Gen (CList a)", it's the same as if you'd write "Gen
(CList b)", and it means "forall b. Gen (CList b)". But that's not
true! The term "arbitrary" cannot have the type "forall b. Gen (CList
b)", because the instance for "Gen (CList c)" requires "(Arbitray c,
Eq c)". That's why GHC wants you to add the constraint.

However, you can make type variables scoped in GHC, by enabling the
"ScopedTypeVariables" extension. So if you add the pragma

{-# LANGUAGE ScopedTypeVariables #-}

as the first line of your module, then the type variables that occur
in the instance declaration scope over the body of the instance, and
your annotations should mean what you originally expected and work
without the extra constraints.

But of course, as has already been stated, the type annotations are
unnecessary here, because GHC can infer everything anyway.

Cheers,
  Andres

-- 
Andres L?h, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com

Registered in England & Wales, OC335890
250 Ice Wharf, 17 New Wharf Road, London N1 9RF, England


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

Message: 4
Date: Fri, 10 Apr 2015 20:04:00 +0100
From: emacstheviking <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Debugging in Haskell
Message-ID:
        <caeieuujwyemdvhr8ln8v-rvusu413epah5swjg0kz++-kcd...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I've used Emacs for 30 years so I guess I am biased!  One of the real plus
points is its auto-indenting, it's great for avoiding problems on that
front IMHO. "Ugly" is subjective I guess... try vim them, YouTube has some
great videos on Vim and Haskell.

https://www.youtube.com/results?search_query=haskell+vim

The Haskell Live video is good.

All the best,
Sean.


On 10 April 2015 at 01:18, Dimitri DeFigueiredo <[email protected]>
wrote:

>  I did try to use Leksah, but did not like the interface. I don't think it
> helped with debugging, but may be mistaken. I'm now using sublime 3 and
> hoping that someday I will be able to use Atom. Emacs appears to be the
> standard, but it is just too ugly for me.
>
> Dimitri
>
>
>
> On 09/04/15 02:03, emacstheviking wrote:
>
>  That's interesting.
>
> I must confess that I find the need to debug in Haskell greatly reduced
> because I tend to design stuff in small incremental steps in ghci / emac in
> a Lisp like way which means that I am reasoning out my code as I write it
> which usually means there are no logical bugs at least.
>
> However I can see the need on occasion to maybe debug into issues relating
> to threads / STM and behaviours between processes in general.
>
> Have you tried using Leksah, the Haskell IDE?
>
>
>
> On 9 April 2015 at 02:21, Dimitri DeFigueiredo <[email protected]>
> wrote:
>
>> I need to improve my Haskell debugging skills. I know of quickcheck, but
>> that's for testing. It seems that:
>>
>> - Debug.Trace and
>> - dynamic breakpoints in GHCi
>>
>> Are the two easy ways to check the state of your program at a specific
>> point in execution.
>> Is there another simple tool that I should know about? Any tips?
>>
>> Thank you,
>>
>> Dimitri
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> _______________________________________________
> Beginners mailing 
> [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/20150410/d5362bdc/attachment-0001.html>

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

Message: 5
Date: Sat, 11 Apr 2015 08:17:13 +1000
From: Stuart Hungerford <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Managing boilerplate code in QuickCheck
        properties...
Message-ID:
        <cag+kmrfxnyckrqr4qn8eaywooev2op48j7mq4kazgw+tesk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi,

I'm using the wonderful QuickCheck and Tasty libraries to test a bunch
of properties (actually axioms for typeclasses):

positivity_suite :: TestTree
positivity_suite = testGroup "positivity axiom" [

  testProperty "Float"
    (axiom_positivity :: Float -> Bool),

  testProperty "(Float, Float)"
    (axiom_positivity :: (Float, Float) -> Bool),

 -- etc  ]



symmetry_suite :: TestTree
symmetry_suite = testGroup "symmetry axiom" [

  testProperty "Float"
    (axiom_symmetry :: Float -> Float -> Bool),

  testProperty "(Float, Float)"
    (axiom_symmetry :: (Float, Float) -> (Float, Float) -> Bool),

  -- etc ]


Over multiple typeclasses, axioms and instance types this leads to a
huge amount of repeated, boilerplate code. I asked an earlier question
on the Haskell Cafe mailing list about testing polymorphic typeclasses
in QuickCheck but I'm realizing the issue is going to crop up beyond
testing typeclass axioms and perhaps beyond testing. I can see several
workarounds for managing the boilerplate code:


1. Define a set of CPP macros for the property type signatures

2. Do the same sort of thing with Template Haskell but with mapping
over a list of desired test types

3. Define a very tedious but succinct set of type aliases allowing
most properties to become more cryptic one-liners


type Pr_F_F = Float -> Float -> Bool

type Pr_F2_F2 = (Float, Float) -> (Float, Float) -> Bool

-- etc, then

testProperty "(Float, Float)"  (axiom_symmetry :: Pr_F2_F2)


How do experienced Haskellers deal with this situation?  I feel I'm
missing something in how I've gone about this.


Thanks,

Stu


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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 82, Issue 10
*****************************************

Reply via email to