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:  What to do next? (Tony Morris)
   2.  suggestions for code improvement (Dennis Raddle)
   3. Re:  Installing Yesod! (Michael Snoyman)


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

Message: 1
Date: Fri, 21 Mar 2014 08:15:05 +1000
From: Tony Morris <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What to do next?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I teach FP for a living for an organisation called NICTA. This is the
material I use primarily https://github.com/NICTA/course

If you can do the easy stuff, fine. For example,
https://github.com/NICTA/course/blob/master/src/Course/List.hs
https://github.com/NICTA/course/blob/master/src/Course/ListZipper.hs
https://github.com/NICTA/course/blob/master/src/Course/StateT.hs

If you want it a bit harder:
https://github.com/NICTA/course/blob/master/src/Course/Parser.hs
https://github.com/NICTA/course/blob/master/src/Course/JsonParser.hs
https://github.com/NICTA/course/blob/master/src/Course/Cheque.hs

But if you can do any of these, then I would say you are not a beginner
anymore:
https://github.com/NICTA/course/blob/master/projects/TicTacToe/TicTacToe.markdown
https://github.com/NICTA/course/blob/master/projects/NetworkServer/NetworkServer.markdown


On 21/03/14 04:17, bruce li wrote:
> Hi, there,
> I'm relatively new to Haskell...well... I mean I haven't done anything
> I believe truely in Haskell. I have gone through materials like Learn
> You a Haskell for Real Good, Real World Haskell, most chapters in
> Haskell Wikibook, Write Yourself Scheme in 48 Hours, Algorithms: A
> Functional Approach and other materials in Haskell Wiki. 
>
> *But... what I feel is that I'm not confident while writing Haskell
> code.* Having gone through all those materials with "magic", I always
> feel I'm writing stupid code and there must be more elegant way...
> And... what's worse, I feel guilty while using IO monad but I simply
> cannot avoid it, like when I try to write code generator for a toy
> compiler, I need to keep state of the registers, which I need IORef...
> Then I feel its not pure anymore but I don't know how to get around it.
>
> I'm wondering if anyone else shares this kind of feeling and what
> should I do next? Could anyone suggest any project to get hands on
> experience with Haskell? 
>
> Another question is that the deeper digging into functional algorithms
> design (reading the book Pearls of Functional Algorithm Design), the
> more ignorant I feel. So how do I make up the basics like fold law,
> list induction etc. Any suggested reading materials?
>
> Well.. I think that's a lot question. Thanks for your patience and
> your kind help.
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


-- 
Tony Morris
http://tmorris.net/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140321/bc51693b/attachment-0001.html>

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

Message: 2
Date: Thu, 20 Mar 2014 18:22:09 -0700
From: Dennis Raddle <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] suggestions for code improvement
Message-ID:
        <cakxlvorzzp5apqzj07rl86my6knb0oxeczrmnaflct70xju...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

This is a fairly complex problem and I don't expect anyone to follow it
all, but I thought I would just post it and see if anyone can immediately
identify unidiomatic Haskell.

The problem is this: I'm writing a program that does backtrack search to
determine musical counterpoint. I begin by laying out a series of "cells"
which are notes of *as yet undetermined* pitch but do have determined begin
time and duration (and also the instrument playing them is known). The
algorithm will find pitches for each cell in order to maximize a fitness
function. Cells can overlap in time.

The search algorithm is allowed to make some cells silent if that improves
the final result.

So each cell has a status which is one of the following "undecided,"
"determined a specific pitch," and "determined to be silent".


data CellStatus = CellUndecided  -- Undecided whether this cell will be a
                                 -- pitch or silent
                | CellSilent     -- It has been decided that this cell will
be
                                 -- silent
                | CellPitch Pitch  -- This cell will be a specific pitch
                  deriving(Show)

The following code deals with only one aspect of the fitness function. When
there are patterns in the music called "octave relations," it makes the
solution a bad one that should be avoided. An octave relation is when some
note, say a C, appears as a following C in a different octave and fclose in
time. It's okay to repeat the same C, just not in a different octave. In
some atonal styles of music octave relations need to be specially handled
or avoided altogether.

So this is an algorithm that determines if any octave relations are
present. There are two kinds of octave relations between a cell A and a
cell B (containing an octave relation). One happens when A and B overlap in
time. Clearly that represent a very close juxtaposition of A and B and it's
illegal. The next kind of octave relation happens when B follows A some
time later, but there are very few intervening notes of other pitches. The
idea is that if *a lot of notes* intervene, it distracts the ear and the
octave relation is not audible. But if only a few intervene between A and
B, the octave relation will really stand out.

Another bit of trickery. Consider the cells that intervene between A and B;
that is, notes that start *after the end of A* and *before the beginning of
B*. Some of those might have a status of CellUndecided. Those notes count
as helping to distract the ear because we know we are eventually going to
fill them in. But cells with a status of CellSilent don't count. And of
course, notes of CellPitch status count as distracting the ear (unless they
represent an octave relation).

Here's the code. If anyone actually wants to run this, I can email you some
test data.

import Data.Maybe
import Data.Map(Map)
import qualified Data.Map as M
import qualified Data.List as L


type Time = Int

type Pitch = Int

data Cell = Cell
 { endTime :: Time
 , cellStatus :: CellStatus
 }           deriving(Show)


data CellStatus = CellUndecided  -- Undecided whether this cell will be a
                                 -- pitch or silent
                | CellSilent     -- It has been decided that this cell will
be
                                 -- silent
                | CellPitch Pitch  -- This cell will be a specific pitch
                  deriving(Show)

-- maps a given Time to a list of Cells that *begin* at that time
type TimeMap = Map Time [Cell]

-- checkOctaveRelations
--
-- Int      ::  all octave relations must be have at least this many
--              intervening notes
-- TimeMap  ::  map of Time to list of Cells at that time
-- 
-- Result True if satisfies the condition that all octave relations
--   have at least proper number of intervening notes (or there are no
--   octave relations), False otherwise.
--
checkOctaveRelations :: Int -> TimeMap -> Bool
checkOctaveRelations condition timeMap =
  all checkOneTime . M.keys $ timeMap
  where
    -- check all notes at one begin time to verify they satisfy the
condition.
    -- note that we assume this function is called with 'beginTime' in
ascending
    -- time order, so we only check notes at or following 'beginTime'
    checkOneTime :: Int -> Bool
    checkOneTime beginTime
      | checkBunch cellsAtBeginTime = False  -- this is the case that among
                                             -- all cells at 'beginTime',
there
                                             -- are octave relations within
                                             -- them
      | otherwise = all checkOneCell cellsAtBeginTime
      where
        cellsAtBeginTime = fromJust . M.lookup beginTime $ timeMap
        checkOneCell :: Cell -> Bool
        checkOneCell cell
          -- the line below checks the case that any overlapping cells have
          -- octave relations
          | any (any (isOctRel cell)) overlappingCells = False
          -- otherwise count the number of intervening cells until the
          -- next octave relation
          | otherwise = case countFollowingNonOctRel cell followingCells of
             Nothing -> True  -- no octave relatios were found following
                              -- 'cell' - so condition is met
             Just count -> count >= condition
          where
            (Cell endTime _) = cell
            followingCells = M.elems . snd . M.split (endTime-1) $ timeMap
            overlappingCells =
              M.elems .
              M.filterWithKey (\k _ -> k > beginTime && k < endTime) $
              timeMap


-- countFollowingNonOctRel
--
--   count the number N of cells that do not have an octave relation
--   with input 'c' before encountering an octave relation. Result is Just
N.
--   if no octave relations are found at all, result is Nothing.
countFollowingNonOctRel :: Cell -> [[Cell]] -> Maybe Int
countFollowingNonOctRel c cellGroups =
  case L.findIndex (\cells -> any (isOctRel c) cells) cellGroups of
    Nothing -> Nothing
    Just idx -> Just . sum . map countCells . take idx $ cellGroups
  where
    countCells :: [Cell] -> Int
    countCells cells = sum . map countFn $ cells
    countFn (Cell _ CellSilent) = 0       -- silent cells are not
distracting; don't count as any
    countFn _ = 1                         -- other cells count as
distracting


-- checkBunch
--
--   Check a group of cells that all occur at the same time for any octave
--   relations in any pair of cells
checkBunch :: [Cell] -> Bool
checkBunch [] = False
checkBunch (c:cs) = (any (\c' -> isOctRel c c') cs) || checkBunch cs


isOctRel :: Cell -> Cell -> Bool
isOctRel cell1 cell2
  | isCellPitch cell1 && isCellPitch cell2 = isOctRel' cell1 cell2
  | otherwise = False
  where
    isOctRel' (Cell _ (CellPitch p1)) (Cell _ (CellPitch p2)) =
      p1 /= p2 && p1 `mod` 12 == p2 `mod` 12


isCellPitch (Cell _ (CellPitch _)) = True
isCellPitch _ = False


isCellSilent (Cell _ CellSilent) = True
isCellSilent _ = False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140320/96605097/attachment-0001.html>

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

Message: 3
Date: Fri, 21 Mar 2014 06:49:16 +0200
From: Michael Snoyman <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Installing Yesod!
Message-ID:
        <caka2jg+qrky50xcq9i6qviqqqdlgt3na0exfgg9iuw3cvgp...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I'll go with "maybe" :)


On Fri, Mar 21, 2014 at 12:07 AM, Gilberto Melfe <[email protected]>wrote:

> Thanks for the reply!
>
> I'm using openSUSE 13.1, and of all the packages "available" when I choose
> to install the Haskell Platform, only the ones unmarked in the image I
> attach to this reply, are not installed.
>
> I didn't install them because they were not selected by default; also I
> thought the ghc package might conflict with other stuff in the Haskell
> Platform (maybe it was standalone version of ghc).
>
> So I guess I should install: ghc, ghc-ghc and ghc-ghc-devel?
>
> Simple Yes/No (Maybe:-)...
>
>
> On Thu, Mar 20, 2014 at 8:20 PM, Michael Snoyman <[email protected]>wrote:
>
>> Are you using the Fedora system installation of GHC by any chance? If so,
>> the problem is that Fedora doesn't include GHC-as-a-library by default. See
>> [1] for more details and how to resolve it.
>>
>> If you're *not* on Fedora, please provide more information on your OS and
>> how you install GHC/Haskell Platform.
>>
>> [1] https://groups.google.com/d/msg/yesodweb/AM8VeHpu8IU/xtzjltFwcEgJ
>>
>> ____________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140321/18e38cbc/attachment.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 69, Issue 32
*****************************************

Reply via email to