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:  A seemingly simple use-case for Template     Haskell (Mario Lang)
   2.  Haskell Platform on OS X, Sierra (Dennis Raddle)
   3. Re:  Haskell Platform on OS X, Sierra (Dennis Raddle)
   4.  Why isn't :t (1+1) Integer (Lai Boon Hui)
   5. Re:  Why isn't :t (1+1) Integer (Alex Belanger)


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

Message: 1
Date: Thu, 29 Sep 2016 16:54:13 +0200
From: Mario Lang <ml...@delysid.org>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] A seemingly simple use-case for
        Template        Haskell
Message-ID: <87k2du3gfe....@fx.delysid.org>
Content-Type: text/plain; charset=utf-8

Frerich Raabe <ra...@froglogic.com> writes:

> On 2016-09-28 15:06, Mario Lang wrote:
>> In a small project of mine, I have this basically auto-generated data
>> type:
>>
>> -- Braille music code only uses the old 6-dot system.  We enumerate all
>> -- possible dot patterns to use the type system to avoid accidentally
>> -- specifying invalid dot patterns in the source code.
>> --
>> -- gen :: String
>> -- gen =
>> --     "data Braille = " ++ intercalate " | " ctors ++ " deriving
>> (Enum, Eq)" where
>> --   ctors = "NoDots" : map ctorName [1..63] where
>> --     ctorName :: Int -> String
>> --     ctorName = (++) "Dot" . concatMap (show . succ) . flip filter
>> [0..5] . testBit
>>
>> data SixDots = NoDots | Dot1 | Dot2 | Dot12 | Dot3 | Dot13 | Dot23 | Dot123
>>              | Dot4 | Dot14 | Dot24 | Dot124 | Dot34 | Dot134 | Dot234
>>              | Dot1234 | Dot5 | Dot15 | Dot25 | Dot125 | Dot35 | Dot135
>>              | Dot235 | Dot1235 | Dot45 | Dot145 | Dot245 | Dot1245 | Dot345
>>              | Dot1345 | Dot2345 | Dot12345 | Dot6 | Dot16 | Dot26 | Dot126
>>              | Dot36 | Dot136 | Dot236 | Dot1236 | Dot46 | Dot146 | Dot246
>>              | Dot1246 | Dot346 | Dot1346 | Dot2346 | Dot12346 | Dot56 | 
>> Dot156
>>              | Dot256 | Dot1256 | Dot356 | Dot1356 | Dot2356 | Dot12356
>>              | Dot456 | Dot1456 | Dot2456 | Dot12456 | Dot3456 | Dot13456
>>              | Dot23456 | Dot123456
>>              deriving (Bounded, Enum, Eq, Read, Show)
>>
>> So, while actually quite simple, this looks like an opportunity to use
>> Template Haskell for me.  In other words, I want to figure out what is
>> necessary to generate this data type with TH, instead of the gen
>> function that basically generates a piece of plain Haskell code.
>
> Here's one way to do it (the 'ctorNames' definition is copied out of
> your comment):
>
> --- Mario.hs ---
> module Mario (makeDotsType) where
>
> import Data.Bits (testBit)
> import Language.Haskell.TH
>
> ctorNames :: [String]
> ctorNames = "NoDots" : map ctorName [1..63]
>   where
>     ctorName :: Int -> String
>     ctorName = (++) "Dot" . concatMap (show . succ) . flip filter
> [0..5] . testBit
>
> makeDotsType :: Q [Dec]
> makeDotsType = do
>     let ctors = map (\n -> NormalC (mkName n) []) ctorNames
>     let instances = map mkName ["Bounded", "Enum", "Eq", "Read", "Show"]
>     return [DataD [] (mkName "SixDots") [] ctors instances]
> ---
>
> --- Main.hs ---
> {-# LANGUAGE TemplateHaskell #-}
>
> import Mario
>
> $(makeDotsType)
> ---
>
> If you compile this with
>
> $ ghc -ddump-splices Main.hs
>
> You can see what type definition that '$(makeDotsType)' expands to.

Oh, thank you!  It could have been so simple...

> For what it's worth, this may not compile with all versions of the TH
> support in GHC; I wrote the above code using GHC 7.10.2.

Works here.

> In general, I find -ddump-splices invaluable when using TH. I use it
> every minute or so to see what code I'm currently generating. What's
> noteworthy is that (as mentioned in the 'Using Template Haskell'
> section of the GHC user guide) that
>
>   You can only run a function at compile time if it is imported from
> another module. That is, you can't define
>   a function in a module, and call it from within a splice in the same
> module.
>
> That's why I used a separate 'Mario' module above.

Yes, I was aware of the need to put the function in a different module.

Thanks again, a working example is really nice to play with.

-- 
CYa,
  ⡍⠁⠗⠊⠕


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

Message: 2
Date: Thu, 29 Sep 2016 13:35:49 -0700
From: Dennis Raddle <dennis.rad...@gmail.com>
To: Haskell Beginners <beginners@haskell.org>
Subject: [Haskell-beginners] Haskell Platform on OS X, Sierra
Message-ID:
        <cakxlvormqd2sedvu6z2lgarb1r-y9dz2wz4rtt2kcck9tj-...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I have been running the Haskell Platform on OS X El Capitan for a few
months. I just upgraded to Sierra and I notice it broke something. For
instance when I run ghci I get

xcrun: error: invalid active developer path ... missing xcrun ....

What's the best way to recover?  Should I uninstall and reinstall Haskell
Platform?

BTW, how DO you uninstall the Haskell Platform on OS X?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160929/78a09350/attachment-0001.html>

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

Message: 3
Date: Thu, 29 Sep 2016 14:10:52 -0700
From: Dennis Raddle <dennis.rad...@gmail.com>
To: Haskell Beginners <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Haskell Platform on OS X, Sierra
Message-ID:
        <CAKxLvoqbpKOo-=538BjmRqyE8-K7jkvsLgi=lpgu7gmay4a...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Solved, I think. I think the fix is to install the command-line developer
tools.

On Thu, Sep 29, 2016 at 1:35 PM, Dennis Raddle <dennis.rad...@gmail.com>
wrote:

> I have been running the Haskell Platform on OS X El Capitan for a few
> months. I just upgraded to Sierra and I notice it broke something. For
> instance when I run ghci I get
>
> xcrun: error: invalid active developer path ... missing xcrun ....
>
> What's the best way to recover?  Should I uninstall and reinstall Haskell
> Platform?
>
> BTW, how DO you uninstall the Haskell Platform on OS X?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160929/2ca3601a/attachment-0001.html>

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

Message: 4
Date: Fri, 30 Sep 2016 07:48:32 +0800
From: Lai Boon Hui <laibo...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Why isn't :t (1+1) Integer
Message-ID:
        <CAJdQgg=d185rvrQgQ14EyKPRFrNQSBkfesF0Yf6Re=Xk5dqH=q...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,
i read that the default type for Num is Integer.
If we specify a type for one of the arguments:
:t (1 + 1::Double) is Double

If we don't, i expect the default type for Num to come into play:
However :t (1 + 1) is Num a => a

Why is that so?

-- 
Best Regards,
Boon Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160930/a8b18910/attachment-0001.html>

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

Message: 5
Date: Thu, 29 Sep 2016 23:47:17 -0400
From: Alex Belanger <i.caught....@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Why isn't :t (1+1) Integer
Message-ID:
        <cadsky2y-pla6ircgtf5m5azf9qjn_65sccq_+mtgxdxpk+n...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Those are not demonstrations of the defaulting rules in action though.

As far as I know, :t is agnostic to those and will keep showing the
original polymorphic version, since you're not in a context where GHC has
to sacrifice the polymorphic type and commit to a monomorphic one using a
default, like when expressions are evaluated.

Also I think that's effective just for the REPL (it uses extended
defaulting rules that are more lax) and is done for convenience. If it was
during a GHC build, you'd get loud warning when something is defaulted.

Try `reverse []` for fun vs. `:t reverse []`.

On Sep 29, 2016 7:48 PM, "Lai Boon Hui" <laibo...@gmail.com> wrote:

> Hi,
> i read that the default type for Num is Integer.
> If we specify a type for one of the arguments:
> :t (1 + 1::Double) is Double
>
> If we don't, i expect the default type for Num to come into play:
> However :t (1 + 1) is Num a => a
>
> Why is that so?
>
> --
> Best Regards,
> Boon Hui
>
> _______________________________________________
> 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/20160929/bd50ac7f/attachment-0001.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 99, Issue 23
*****************************************

Reply via email to