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: Case Expressions (Nathan Holden)
2. Re: Haskell Generic Function Question (Ertugrul Soeylemez)
3. Re: [Haskell-cafe] can someone point me to more help about
Database.HDBC.ODBC? (Michael Mossey)
4. Maybe a and Maybe t (Ivan Uemlianin)
5. Re: Maybe a and Maybe t (Andrew Wagner)
6. Re: Maybe a and Maybe t (Lee Duhem)
----------------------------------------------------------------------
Message: 1
Date: Fri, 29 May 2009 10:38:23 -0400
From: Nathan Holden <[email protected]>
Subject: Re: [Haskell-beginners] Case Expressions
To: Thomas Friedrich <[email protected]>, [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Yes. I did. In fact, that's what it looks like. But in general I also derive
Enum, and use Ints instead, because that's how I conveniently switch between
notes and intervals.
On Fri, May 29, 2009 at 10:27 AM, Thomas Friedrich <[email protected]> wrote:
> Hi Nathan,
>
> do you mean something like the following?
>
> data Interval = Unison
> | MinorSecond
> | MajorSecond
> | MinorThird
> | MajorThird
> deriving (Show)
>
> data BasicInterval = BasicUnison
> | Second
> | Third
> | Fourth
> deriving (Show)
>
> inter2basic :: Interval -> BasicInterval
> inter2basic x = case x of
> Unison -> BasicUnison
> MinorSecond -> Second
> MajorSecond -> Second
> MinorThird -> Third
> MajorThird -> Third
>
>
> Happy Hacking,
> Thomas
>
>
>
> Nathan Holden wrote:
>
>> I've been playing with my musical interval problem from before, and I got
>> a little further, but I came up with a problem.
>>
>> I have two types-- Interval and BasicInterval.
>>
>> Interval has 12 constructors, Unison, MinorSecond, MajorSecond,
>> MinorThird, et cetera.
>> BasicInterval has 8 constructors, BasicUnison, Second, Third, Fourth, and
>> so on.
>>
>> I want to be able to convert between them somewhat;
>>
>> I have function interToBasic, which at the moment looks like:
>>
>> interToBasic :: Interval -> BasicInterval
>> interToBasic a = if (b == 1 || b == 2) then Second
>> else if (b == 3 || b == 4) then Third
>> ..
>> where b = fromEnum a
>>
>> What I wanted to do, and figure is probably doable, but I can't seem to
>> find it, is to say something like
>>
>> case (fromEnum a) of
>> 1 || 2 -> Second
>> 3 || 4 -> Third
>> ..
>>
>> Is this doable? If so, what's the syntax?
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> 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/20090529/0d25bb03/attachment-0001.html
------------------------------
Message: 2
Date: Sat, 30 May 2009 01:32:48 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: [Haskell-beginners] Re: Haskell Generic Function Question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Jeff Wheeler <[email protected]> wrote:
> > f = \x -> (x `quot` 10, x `mod` 10)
>
> Your function f is almost the same as divMod in Prelude. Also, using a
> lambda function seems odd; this is simpler:
>
> > f x = (x `quot` 10, x `mod` 10)
Hmm, simplicity.
f = (`quot` 10) &&& (`mod` 10)
SCNR.
Greets,
Ertugrul.
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/
------------------------------
Message: 3
Date: Sat, 30 May 2009 00:09:23 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] Re: [Haskell-cafe] can someone point me
to more help about Database.HDBC.ODBC?
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
This is on Windows, by the way. Do you know the equivalent file names and
locations? What is DSN?
Thanks,
Mike
Ðвгений ТаÑаÑов wrote:
> Usually you should pass only DSN name in the string, if you used InnoDB
> database in MySQL.
>
> For example, /etc/odbc.ini file:
> ;
> ; odbc.ini configuration for MyODBC and MyODBC 3.51 Drivers
> ;
> [.....]
>
> [Default]
> Driver = MySQL
> Description = MySQL ODBC 3.51 Driver DSN
> Server = localhost
> Port =
> User = root
> Password =
> Database = test
> Option = 3
> Socket =
>
> [......]
>
> Next step, you can test a connection with command:
> $ isql Default
> +---------------------------------------+
> | Connected! |
> | |
> | sql-statement |
> | help [tablename] |
> | quit |
> | |
> +---------------------------------------+
> SQL>
>
> And finally, the haskell code:
>
> conn <- connectODBC "DSN=Default;"
>
>
------------------------------
Message: 4
Date: Sat, 30 May 2009 21:37:05 +0100
From: Ivan Uemlianin <[email protected]>
Subject: [Haskell-beginners] Maybe a and Maybe t
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Dear All
I have just started learning Haskell, using the O'Reilly book Real World
Haskell [1]. I'm finding it a very exciting language, and I'm working
my way painstakingly through the book (I'm up to the exercises at the
end of Chapter 3).
I have a query based on some code from the book. This question has been
asked on the book web site [2], but no answer. I have also Googled
about and scanned the documentation.
So, here is some code (quoted from [3]): two implementations of a
function to return the second element of a list. I have commented out
the type signatures.
-- file: rwh_examples2/ch03/MySecond.hs
-- safeSecond :: [a] -> Maybe a
safeSecond [] = Nothing
safeSecond xs = if null (tail xs)
then Nothing
else Just (head (tail xs))
-- tidySecond :: [a] -> Maybe a
tidySecond (_:x:_) = Just x
tidySecond _ = Nothing
My query concerns the inferred types of these functions --- the types
inferred when the type signatures are commented out. Here's a ghci session:
Prelude> :load seconds.hs
[1 of 1] Compiling Main ( seconds.hs, interpreted )
Ok, modules loaded: Main.
*Main>
*Main> :type safeSecond
safeSecond :: [a] -> Maybe a
*Main>
*Main> :type tidySecond
tidySecond :: [t] -> Maybe t
*Main>
Why is safeSecond type [a] -> Maybe a, and tidySecond type [t] -> Maybe
t? I mean why does one use "a" and the other "t"? What does it mean?
If I change the order of the two functions in the source file,
safeSecond still uses "a" and tidySecond still uses "t".
Can anyone help, or point me to the right place in the documentation?
In the meantime, if I find out from elsewhere I'll report back here.
Thanks and best wishes
Ivan
[1] http://book.realworldhaskell.org/
[2]
http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html#comment8512
[3]
http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html#deftypes.morecontrolled
--
============================================================
Ivan A. Uemlianin
Speech Technology Research and Development
[email protected]
www.llaisdy.com
llaisdy.wordpress.com
www.linkedin.com/in/ivanuemlianin
"Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
(Schiller, Beethoven)
============================================================
------------------------------
Message: 5
Date: Sat, 30 May 2009 16:50:39 -0400
From: Andrew Wagner <[email protected]>
Subject: Re: [Haskell-beginners] Maybe a and Maybe t
To: Ivan Uemlianin <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Good question, but I'm afraid the answer will be a bit disappointing. The
real answer is, it doesn't matter - the following types are all the same:
a -> a
b -> b
t -> t
supercalifragilisticexpialodocious -> supercalifragilisticexpialodocious
As for why it actually happens in this case, it's no doubt related to the
particular algorithm ghci uses to do the type inference.
On Sat, May 30, 2009 at 4:37 PM, Ivan Uemlianin <[email protected]> wrote:
> Dear All
>
> I have just started learning Haskell, using the O'Reilly book Real World
> Haskell [1]. I'm finding it a very exciting language, and I'm working my
> way painstakingly through the book (I'm up to the exercises at the end of
> Chapter 3).
>
> I have a query based on some code from the book. This question has been
> asked on the book web site [2], but no answer. I have also Googled about
> and scanned the documentation.
>
> So, here is some code (quoted from [3]): two implementations of a function
> to return the second element of a list. I have commented out the type
> signatures.
>
> -- file: rwh_examples2/ch03/MySecond.hs
>
> -- safeSecond :: [a] -> Maybe a
>
> safeSecond [] = Nothing
> safeSecond xs = if null (tail xs)
> then Nothing
> else Just (head (tail xs))
>
> -- tidySecond :: [a] -> Maybe a
>
> tidySecond (_:x:_) = Just x
> tidySecond _ = Nothing
>
> My query concerns the inferred types of these functions --- the types
> inferred when the type signatures are commented out. Here's a ghci session:
>
> Prelude> :load seconds.hs
> [1 of 1] Compiling Main ( seconds.hs, interpreted )
> Ok, modules loaded: Main.
> *Main>
> *Main> :type safeSecond
> safeSecond :: [a] -> Maybe a
> *Main>
> *Main> :type tidySecond
> tidySecond :: [t] -> Maybe t
> *Main>
>
> Why is safeSecond type [a] -> Maybe a, and tidySecond type [t] -> Maybe t?
> I mean why does one use "a" and the other "t"? What does it mean?
> If I change the order of the two functions in the source file, safeSecond
> still uses "a" and tidySecond still uses "t".
>
> Can anyone help, or point me to the right place in the documentation? In
> the meantime, if I find out from elsewhere I'll report back here.
>
> Thanks and best wishes
>
> Ivan
>
> [1] http://book.realworldhaskell.org/
> [2]
> http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html#comment8512
> [3]
> http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html#deftypes.morecontrolled
>
>
> --
> ============================================================
> Ivan A. Uemlianin
> Speech Technology Research and Development
>
> [email protected]
> www.llaisdy.com
> llaisdy.wordpress.com
> www.linkedin.com/in/ivanuemlianin
>
> "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
> (Schiller, Beethoven)
> ============================================================
>
> _______________________________________________
> 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/20090530/11c69ba9/attachment-0001.html
------------------------------
Message: 6
Date: Sun, 31 May 2009 08:29:01 +0800
From: Lee Duhem <[email protected]>
Subject: Re: [Haskell-beginners] Maybe a and Maybe t
To: Andrew Wagner <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Sun, May 31, 2009 at 4:50 AM, Andrew Wagner <[email protected]> wrote:
> Good question, but I'm afraid the answer will be a bit disappointing. The
> real answer is, it doesn't matter - the following types are all the same:
> a -> a
> b -> b
> t -> t
> supercalifragilisticexpialodocious -> supercalifragilisticexpialodocious
And by the way, they are called 'type variables', as other kind of variables,
when without name conflict, their names don't matter.
lee
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 11, Issue 20
*****************************************