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: Haskell -> JavaScript -> nodejs (Martin Vlk)
2. Structural restrictions in type constructor (Matt Williams)
3. Re: Structural restrictions in type constructor (Martin Vlk)
4. Re: Structural restrictions in type constructor (Imants Cekusins)
5. Re: Structural restrictions in type constructor (Martin Vlk)
6. Re: Structural restrictions in type constructor (Imants Cekusins)
----------------------------------------------------------------------
Message: 1
Date: Sun, 21 Jun 2015 20:02:11 +0000
From: Martin Vlk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Haskell -> JavaScript -> nodejs
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
Thanks, in the end I was able to figure it out, here is the code:
(https://github.com/martinvlk/ghcjs-node-minimal)
{-# LANGUAGE JavaScriptFFI,
OverloadedStrings #-}
module Main (main) where
import GHCJS.Types
import GHCJS.Foreign
foreign import javascript unsafe "require($1)"
require :: JSString -> IO (JSRef a)
foreign import javascript unsafe "$1.hostname()"
hostname :: JSRef a -> IO JSString
main :: IO ()
main = require "os" >>= hostname
>>= \h -> putStrLn $ "Our hostname is '"
++ (fromJSString h) ++ "'"
Martin
Sumit Sahrawat, Maths & Computing, IIT (BHU):
> Better try on the cafe. cc-ing.
>
> On 20 June 2015 at 15:26, Martin Vlk <[email protected]> wrote:
>
>> I made some progress - in order for Haskell modules to work with ghcjs
>> you need to use cabal with the --ghcjs flag to install them.
>>
>> Martin
>>
>> Martin Vlk:
>>> Hi,
>>> I can successfully compile a basic Hello World into JavaScript with
>>> ghcjs and run it with nodejs.
>>> But what I ultimately need to do is write a nodejs module in Haskell and
>>> compile down to JavaScript with ghcjs. I need to be able to require
>>> other nodejs modules as well.
>>>
>>> Could somebody point me in the right direction? E.g. what approach and
>>> libraries to use...
>>>
>>> I have tried a simple thing with jsaddle/lens, but when I try to compile
>>> with ghcjs it is not finding the imported modules, even though when
>>> compiling with ghc it does find them (they are installed using cabal).
>>>
>>> Many Thanks
>>> Martin
>>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
------------------------------
Message: 2
Date: Mon, 22 Jun 2015 10:29:40 +0000
From: Matt Williams <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Structural restrictions in type
constructor
Message-ID:
<caftvgqbbwqr-1xggautxjzo8xmkxzab6yefxqsj1y4h6lok...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150622/15b19e23/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 22 Jun 2015 10:49:05 +0000
From: Martin Vlk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Structural restrictions in type
constructor
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
I would think that it is not possible to use types to constrain the
values of data. I.e. type signature can be only used to constraint
types, not values.
But I am a beginner myself, so see if someone more experienced can shed
light here.
Martin
Matt Williams:
> 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
>
------------------------------
Message: 4
Date: Mon, 22 Jun 2015 13:29:36 +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:
<CAP1qinZSL=btypj7ox-t-308v32ogdzi+6d1gy9rj1q9kc+...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
we could use pattern matched constructor:
module PairsMatched where
data MyP t = MyP (t,t)(t,t) deriving Show
myP_ctor:: Eq t => (t,t)->(t,t)->MyP t
myP_ctor (a1,a2) (a3,a4)
| a1 == a4 && a2 == a3 = MyP (a1,a2) (a3,a4)
| otherwise = error "mismatched pairs"
------------------------------
Message: 5
Date: Mon, 22 Jun 2015 11:34:40 +0000
From: Martin Vlk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Structural restrictions in type
constructor
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
But this is checking the values in the implementation, not a type level
build time guarantee, isn't it?
M
Imants Cekusins:
> we could use pattern matched constructor:
>
> module PairsMatched where
>
> data MyP t = MyP (t,t)(t,t) deriving Show
>
>
> myP_ctor:: Eq t => (t,t)->(t,t)->MyP t
> myP_ctor (a1,a2) (a3,a4)
> | a1 == a4 && a2 == a3 = MyP (a1,a2) (a3,a4)
> | otherwise = error "mismatched pairs"
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
------------------------------
Message: 6
Date: Mon, 22 Jun 2015 13:36:03 +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:
<CAP1qinZrUr6KVcPa0Er2XoAvvLkF3RFsOrYV_=021pttg15...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
> But this is checking the values in the implementation, not a type level
build time guarantee, isn't it?
yep, correct. Could be caught by unit tests though :-P
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 84, Issue 36
*****************************************