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.  Setup.hs woes (Ramnath R Iyer)
   2.  Traversable Instance of the Constant type (Atrudyjane)


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

Message: 1
Date: Wed, 19 Apr 2017 16:21:58 +0000
From: Ramnath R Iyer <casual.d...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Setup.hs woes
Message-ID:
        <CACL-Fmyr3JkGwUvkkqCe83VJa17T1=ohytygcajdnsjg5jd...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello,

I've been having some trouble with Setup.hs and could use some help. I'm
using stack for building my project, and would like to auto-generate an
HTML file as part of the build process. I'm able to specify hooks in
Setup.hs to do this, but I'm running into problems.

1. I'm not sure what the "correct" or suitable paths are for publishing
HTML documentation. The closest I could find was the doc dir on the install
path (see below). Should the HTML be created in a built folder and later
copied over to an install/dist dir? The semantics associated with each of
these is not clear to me.

2. I played around with some hooks. I was able to generate the HTML file in
the installation's doc dir, but it looks like that dir is only created as
part of the install hook (naturally), whereas the install hook is never
triggered by `stack build`. (The code below never executes if I use the
instHook.) What is the right hook to use, and how?

import Distribution.PackageDescription (PackageDescription)
import Distribution.Simple (defaultMainWithHooks, simpleUserHooks)
import Distribution.Simple.InstallDirs (InstallDirs(..), docdir)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..),
installDirTemplates, fromPathTemplate)
import Distribution.Simple.Setup (InstallFlags)
import Distribution.Simple.UserHooks (UserHooks, instHook)
import System.Exit (ExitCode(..))
import System.Process (system)

main :: IO ()
main = defaultMainWithHooks simpleUserHooks { instHook = readme } -- does
not get invoked; postBuild does work, but where to put the generated file?

readme :: PackageDescription -> LocalBuildInfo -> UserHooks -> InstallFlags
-> IO ()
readme _ (LocalBuildInfo { installDirTemplates = InstallDirs { docdir =
docdir' }}) _ _ = do
  putStrLn "Generating README.html from README.md..."
  exitCode <- system $ "./doc/generate " ++ (show destination)
  case exitCode of ExitSuccess   -> return ()
                   ExitFailure _ -> fail "README.html could not be
generated from README.md"
  return ()
    where destination = fromPathTemplate docdir'

***

(Apologies if this is a duplicate email, wasn't sure if this already got
sent previously.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170419/451c7081/attachment-0001.html>

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

Message: 2
Date: Thu, 20 Apr 2017 01:53:05 -0400
From: Atrudyjane <atrudyj...@protonmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Traversable Instance of the Constant type
Message-ID:
        
<80UdLI1sUOnx-ehLufWkeUeOdHHrnubv8bRr3w8uuNM0TJizIPj-rb3CiCEuLFabbUw-jgYZhdYUSAuAIzBQ3AwTcj9x9a7mWSIl3L2pf_c=@protonmail.com>
        
Content-Type: text/plain; charset="utf-8"

Pretty sure I'm getting bogged down on something simple, but how does the 
traverse function actually embed the Constant type in the f context passed to 
it? Or is it the pure defined in the f context that's being called?

Thank you,
Andrea

newtype Constant a b = Constant { getConstant :: a } deriving (Eq, Show)

instance Functor (Constant a) where
fmap f (Constant a) = Constant a

instance Monoid a => Applicative (Constant a) where
pure a = Constant { getConstant = mempty }
Constant a <*> Constant b = Constant { getConstant = a `mappend` b }

instance Foldable (Constant a) where
foldMap f (Constant a) = mempty

instance Traversable (Constant a) where
traverse f (Constant a) = pure $ Constant a

λ> traverse (\x -> Just x) (Constant 1)
Just (Constant {getConstant = 1})

Sent with [ProtonMail](https://protonmail.com) Secure Email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170420/1fa6e012/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 106, Issue 14
******************************************

Reply via email to