Send Beginners mailing list submissions to
[email protected]
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
[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: Structural restrictions in type constructor
(Kostiantyn Rybnikov)
2. Re: Structural restrictions in type constructor (Imants Cekusins)
3. Re: Structural restrictions in type constructor
(Kostiantyn Rybnikov)
4. ghc-mod and cabal "could not find module Prelude" (Alan Buxton)
----------------------------------------------------------------------
Message: 1
Date: Tue, 23 Jun 2015 15:54:07 +0300
From: Kostiantyn Rybnikov <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Structural restrictions in type
constructor
Message-ID:
<caabahfsxs_galby88ck5s-od8j-edumpx0e9uaswujpzjk3...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi Matt. I don't know how bad is this, but here's what I came up with.
In order to be able to ask types to make sure something about values (their
equality), you might want to create a type, which contains a value in its
type-parameter, and then ask that types are equal if you want some equality
property in datatype. Here's an example:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
module Main where
import GHC.TypeLits
newtype TypeValInt (n::Nat) = TypeValInt Int
deriving (Show)
one :: TypeValInt 1
one = TypeValInt 1
two :: TypeValInt 2
two = TypeValInt 2
data MyP a b = MyP (TypeValInt a, TypeValInt b) (TypeValInt b, TypeValInt a)
deriving (Show)
main :: IO ()
main = do
putStrLn "Hello!"
print (MyP (one, two) (two, one))
-- | this will error:
-- print (MyP (one, two) (one, one))
print (MyPGen (one, two) (two, one))
-- | this will error:
-- print (MyPGen (one, two) (one, one))
class TypeVal (g :: a -> *)
instance TypeVal TypeValInt
data MyPGen a b = forall g. (TypeVal g, Show (g a), Show (g b))
=> MyPGen (g a, g b) (g b, g a)
deriving instance Show (MyPGen a b)
On Mon, Jun 22, 2015 at 1:29 PM, Matt Williams <[email protected]
> wrote:
> Dear All,
>
> I wonder if/ how this is possible?
>
> I have a constructor which takes 2 pairs of type t).
>
> However, I want to ensure that the pairs are matched:
>
> MyP = MyP (t, t) (t, t)
>
> But where the first pair contains the same elements as the second, but
> reversed in order.
>
> Any help much appreciated.
>
> BW,
> Matt
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150623/c695334c/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 23 Jun 2015 16:05:11 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Structural restrictions in type
constructor
Message-ID:
<cap1qinyns8ap0dst2nbpmkov61_wwtgj521q7ywu0fbpdya...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On 23 June 2015 at 14:54, Kostiantyn Rybnikov <[email protected]> wrote:
> Hi Matt. I don't know how bad is this, but here's what I came up with.
...
this modified for IO version accepts any input, including that which
should have caused error:
or did I do something wrong?
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
module PairsMatchedKR where
import GHC.TypeLits
data TypeValInt (n::Nat) = TypeValInt Int
deriving (Show)
one :: TypeValInt 1
one = TypeValInt 1
two :: TypeValInt 2
two = TypeValInt 2
data MyP a b = MyP (TypeValInt a, TypeValInt b) (TypeValInt b, TypeValInt a)
deriving (Show)
main :: IO ()
main = do
putStrLn "Hello!"
x1 <- getLine
x2 <- getLine
x3 <- getLine
x4 <- getLine
print (MyP (tvi x1, tvi x2) (tvi x3, tvi x4))
class TypeVal (g :: a -> *)
instance TypeVal TypeValInt
data MyPGen a b = forall g. (TypeVal g, Show (g a), Show (g b))
=> MyPGen (g a, g b) (g b, g a)
deriving instance Show (MyPGen a b)
tvi:: String -> TypeValInt (n::Nat)
tvi = TypeValInt . read
------------------------------
Message: 3
Date: Tue, 23 Jun 2015 17:33:06 +0300
From: Kostiantyn Rybnikov <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Structural restrictions in type
constructor
Message-ID:
<caabahfqk_h+keuqm+kszjqr4ocyfk+t6g45g++2evraqtvx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Imants,
You are right. The problem is not in IO here, it's that if you have access
to data-constructor, you can do things like:
six :: TypeValInt 6
six = TypeValInt 5
Initially, I was making an assumption that you won't be using a
data-constructor. After thinking about it a bit, I should note that my code
isn't much different from just using a "smart constructor" approach, e.g.
hiding a real MyP constructor, and instead providing a function:
mkMyP (a, b) = MyP (a, b) (b, a)
and exporting only this function. This would make sure all your users only
create a valid set of data.
On Tue, Jun 23, 2015 at 5:05 PM, Imants Cekusins <[email protected]> wrote:
> On 23 June 2015 at 14:54, Kostiantyn Rybnikov <[email protected]> wrote:
> > Hi Matt. I don't know how bad is this, but here's what I came up with.
> ...
>
> this modified for IO version accepts any input, including that which
> should have caused error:
>
> or did I do something wrong?
>
>
> {-# LANGUAGE DataKinds #-}
> {-# LANGUAGE KindSignatures #-}
> {-# LANGUAGE ExistentialQuantification #-}
> {-# LANGUAGE PolyKinds #-}
> {-# LANGUAGE StandaloneDeriving #-}
>
> module PairsMatchedKR where
>
> import GHC.TypeLits
>
> data TypeValInt (n::Nat) = TypeValInt Int
> deriving (Show)
>
> one :: TypeValInt 1
> one = TypeValInt 1
>
> two :: TypeValInt 2
> two = TypeValInt 2
>
> data MyP a b = MyP (TypeValInt a, TypeValInt b) (TypeValInt b, TypeValInt
> a)
> deriving (Show)
>
> main :: IO ()
> main = do
> putStrLn "Hello!"
> x1 <- getLine
> x2 <- getLine
> x3 <- getLine
> x4 <- getLine
>
> print (MyP (tvi x1, tvi x2) (tvi x3, tvi x4))
>
> class TypeVal (g :: a -> *)
> instance TypeVal TypeValInt
>
> data MyPGen a b = forall g. (TypeVal g, Show (g a), Show (g b))
> => MyPGen (g a, g b) (g b, g a)
> deriving instance Show (MyPGen a b)
>
>
> tvi:: String -> TypeValInt (n::Nat)
> tvi = TypeValInt . read
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150623/31372449/attachment-0001.html>
------------------------------
Message: 4
Date: Tue, 23 Jun 2015 15:48:18 +0100
From: "Alan Buxton" <[email protected]>
To: <[email protected]>
Subject: [Haskell-beginners] ghc-mod and cabal "could not find module
Prelude"
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi
I've recently set up a new Haskell working environment on Ubuntu 14.04. I
installed the Ubuntu packaged version of Haskell platform.
My problem is that I can't now get ghc-mod check to work if there is a cabal
file in the current directory.
I am using:
* ghc-mod 5.2.1.2 compiled by GHC 7.6.3
* cabal 1.16.0.2
See below an extract of trying to run ghc-mod check in a directory that was
empty until I just ran cabal init in it:
~/tmp-ghc-mod$ ls
Setup.hs tmp-ghc-mod.cabal
~/tmp-ghc-mod$ ghc-mod check Setup.hs
Setup.hs:1:1:Could not find module `Prelude'It is a member of the hidden
package `base'.Perhaps you need to add `base' to the build-depends in your
.cabal file.It is a member of the hidden package `haskell98-2.0.0.2'.Perhaps
you need to add `haskell98' to the build-depends in your .cabal file.It is a
member of the hidden package `haskell2010-1.1.1.0'.Perhaps you need to add
`haskell2010' to the build-depends in your .cabal file.Use -v to see a list
of the files searched for.
~/tmp-ghc-mod$ mv tmp-ghc-mod.cabal tmp-ghc-mod.cabal.NOT
~/tmp-ghc-mod$ ls
dist Setup.hs tmp-ghc-mod.cabal.NOT
~/tmp-ghc-mod$ ghc-mod check Setup.hs
Setup.hs:2:1:Warning: Top-level binding with no type signature: main :: IO
()
~/tmp-ghc-mod$
So. ghc-mod behaves as expected when there is no cabal file, but doesn't
behave as expected if there is a cabal file.
My google fu isn't helping me out on this: the only issues I have seen are
to do with a change in format of the cabal file in newer versions of cabal.
Any ideas?
Thanks
Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150623/29ac55de/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 84, Issue 39
*****************************************