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:  recursive 'let' ? (Magnus Therning)
   2.  Windows x64 ? (John M. Dlugosz)
   3.  Convert my own types to the Haskell types using  typeclass
      (ke dou)
   4. Re:  Convert my own types to the Haskell types using
      typeclass (Bob Ippolito)
   5. Re:  Convert my own types to the Haskell types using
      typeclass (ke dou)


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

Message: 1
Date: Fri, 11 Apr 2014 17:28:15 +0200
From: Magnus Therning <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] recursive 'let' ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On Thu, Apr 10, 2014 at 07:12:25PM -0500, John M. Dlugosz wrote:
> I understand that the definitions introduced by 'let' can be
> recursive, even mutually recursive among several names.  Why would
> you want to do that?  I saw contrived examples, and wonder why the
> authors never show a realistic example.
> 
>       let b = f a c
>           c = f a b
>       in ...
> 
> I see that makes sense in light of lazy evaluation: b is really an
> alias for a (recursive) function, not a value that needs to find
> fixed points.
> 
> Is this used for common idioms and problem-solving approaches in
> Haskell?

I can't really point to any idiomatic use, or problem-solving
approaches, but it is a terribly useful feature since one of the
effects is that the order of introducing functions/values isn't
significant.  So you are free to write and structure your code in the
manner that makes most sense to you.

Having just ventured back into OCaml and dipping my toes in F# I
immediately ran into errors caused by their non-recursive `let`, and
the requirement to introduce values/types before use.

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4 
email: [email protected]   jabber: [email protected]
twitter: magthe               http://therning.org/magnus

The results point out the fragility of programmer expertise: advanced
programmers have strong expectations about what programs should look like,
and when those expectations are violated--in seemingly innocuous
ways--their performance drops drastically.
     -- Elliot Soloway and Kate Ehrlich
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140411/76881114/attachment-0001.sig>

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

Message: 2
Date: Fri, 11 Apr 2014 11:25:27 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Windows x64 ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

The Haskell Platform has a single download link for "Windows" which seems to be 
32-bit 
only.  But GHC is available for Win x64.  Their site dissuades downloading 
their 
installation and recommends getting Haskell Platform instead.  So, is there an 
easy way to 
get 64-bit versions of compiler or compiled executables so produced?



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

Message: 3
Date: Fri, 11 Apr 2014 12:50:45 -0400
From: ke dou <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Convert my own types to the Haskell types
        using   typeclass
Message-ID:
        <cag1_ucrfuj+rijd78duph2yenitow-re1xv3w1s69ox4pb7...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

I want to define a typeclass that can convert my own types like MyBool,
MyInt, MyOption to according Haskell types -- Bool, Int, Maybe.

Currently I can convert the first two types, but for MyOption, I don't how
to do, since it is a polymophic type.

Here is my toy program:
--------------------------------------------------------------
{-# LANGUAGE TypeFamilies #-}

module Coercible where

import qualified Prelude

data MyBool = MyTrue | MyFalse
data MyInt = Zero | One | Two
data MyOption a =
   Some a
 | None

class Coercible a where
  type Return a :: *
  toHaskell :: a -> (Return a)

instance Coercible MyBool where
  type Return MyBool = Prelude.Bool
  toHaskell MyTrue = Prelude.True
  toHaskell MyFalse = Prelude.False

instance Coercible MyInt where
  type Return MyInt = Prelude.Int
  toHaskell Zero = 0
  toHaskell One = 1
  toHaskell Two = 2

instance Coercible (MyOption a) where
  type Return (MyOption a) = Prelude.Maybe a
  toHaskell (Some a) = Prelude.Just a
  toHaskell None = Prelude.Nothing
--------------------------------------------------------------------------
The problem occurs when I am trying to use "toHaskell (Some MyBool)", the
error message is "Not in scope: data constructor `MyBool'".
Any hints will be appreciated !!

Best,
--Ke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140411/dbc7b037/attachment-0001.html>

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

Message: 4
Date: Fri, 11 Apr 2014 10:05:03 -0700
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Convert my own types to the Haskell
        types using typeclass
Message-ID:
        <cacwmpm_tcdaclkwsuvwqhmkcar2qfkbyc123sul-4b0r6fy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Fri, Apr 11, 2014 at 9:50 AM, ke dou <[email protected]> wrote:

> Hi,
>
> I want to define a typeclass that can convert my own types like MyBool,
> MyInt, MyOption to according Haskell types -- Bool, Int, Maybe.
>
> Currently I can convert the first two types, but for MyOption, I don't how
> to do, since it is a polymophic type.
>
> Here is my toy program:
> --------------------------------------------------------------
> {-# LANGUAGE TypeFamilies #-}
>
> module Coercible where
>
> import qualified Prelude
>
> data MyBool = MyTrue | MyFalse
> data MyInt = Zero | One | Two
> data MyOption a =
>    Some a
>  | None
>
> class Coercible a where
>   type Return a :: *
>   toHaskell :: a -> (Return a)
>
> instance Coercible MyBool where
>   type Return MyBool = Prelude.Bool
>   toHaskell MyTrue = Prelude.True
>   toHaskell MyFalse = Prelude.False
>
> instance Coercible MyInt where
>   type Return MyInt = Prelude.Int
>   toHaskell Zero = 0
>   toHaskell One = 1
>   toHaskell Two = 2
>
> instance Coercible (MyOption a) where
>   type Return (MyOption a) = Prelude.Maybe a
>   toHaskell (Some a) = Prelude.Just a
>   toHaskell None = Prelude.Nothing
> --------------------------------------------------------------------------
> The problem occurs when I am trying to use "toHaskell (Some MyBool)", the
> error message is "Not in scope: data constructor `MyBool'".
> Any hints will be appreciated !!
>

`Some MyBool` isn't valid Haskell. MyBool is the name of a type, there's no
binding or constructor with that name. `toHaskell (Some MyTrue)` evaluates
to `Just MyTrue` as expected.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140411/b7e1b5bb/attachment-0001.html>

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

Message: 5
Date: Fri, 11 Apr 2014 13:13:35 -0400
From: ke dou <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Convert my own types to the Haskell
        types using typeclass
Message-ID:
        <cag1_ucrvnhubvt7s4awcvvsw_yo_e7uq2dslgnzhptniz6s...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thank you, Bob.
I also noticed that, but don't know how to fix it.
Any suggestions?

--Ke


On Fri, Apr 11, 2014 at 1:05 PM, Bob Ippolito <[email protected]> wrote:

> On Fri, Apr 11, 2014 at 9:50 AM, ke dou <[email protected]> wrote:
>
>> Hi,
>>
>> I want to define a typeclass that can convert my own types like MyBool,
>> MyInt, MyOption to according Haskell types -- Bool, Int, Maybe.
>>
>> Currently I can convert the first two types, but for MyOption, I don't
>> how to do, since it is a polymophic type.
>>
>> Here is my toy program:
>> --------------------------------------------------------------
>> {-# LANGUAGE TypeFamilies #-}
>>
>> module Coercible where
>>
>> import qualified Prelude
>>
>> data MyBool = MyTrue | MyFalse
>> data MyInt = Zero | One | Two
>> data MyOption a =
>>    Some a
>>  | None
>>
>> class Coercible a where
>>   type Return a :: *
>>   toHaskell :: a -> (Return a)
>>
>> instance Coercible MyBool where
>>   type Return MyBool = Prelude.Bool
>>   toHaskell MyTrue = Prelude.True
>>   toHaskell MyFalse = Prelude.False
>>
>> instance Coercible MyInt where
>>   type Return MyInt = Prelude.Int
>>   toHaskell Zero = 0
>>   toHaskell One = 1
>>   toHaskell Two = 2
>>
>> instance Coercible (MyOption a) where
>>   type Return (MyOption a) = Prelude.Maybe a
>>   toHaskell (Some a) = Prelude.Just a
>>   toHaskell None = Prelude.Nothing
>> --------------------------------------------------------------------------
>> The problem occurs when I am trying to use "toHaskell (Some MyBool)", the
>> error message is "Not in scope: data constructor `MyBool'".
>> Any hints will be appreciated !!
>>
>
> `Some MyBool` isn't valid Haskell. MyBool is the name of a type, there's
> no binding or constructor with that name. `toHaskell (Some MyTrue)`
> evaluates to `Just MyTrue` as expected.
>
> _______________________________________________
> 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/20140411/3a8f5361/attachment.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 70, Issue 24
*****************************************

Reply via email to