From dennis.raddle at gmail.com Mon Aug 1 08:06:05 2016
From: dennis.raddle at gmail.com (Dennis Raddle)
Date: Mon, 1 Aug 2016 01:06:05 -0700
Subject: [Haskell-beginners] reading lines with history from bash
terminal in OS X
In-Reply-To:
References:
Message-ID:
I'm looking over haskeline. It looks like I have to modify some of my code
that is in the IO monad right now. I use 'evaluate' in several places, and
also 'evaluate $ force', to make sure that IO exceptions are encountered
where I can catch them. Can I use 'evaluate' with InputT? I'm muddled
headed about what to do. I guess I would lift 'evaluate' into the inner
monad? I am not sure what those words mean. How would I catch IO exceptions?
On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle
wrote:
> Thanks. I'll install haskeline
>
> On Thu, Jul 28, 2016 at 5:05 PM, David McBride wrote:
>
>> You will have to use the haskeline library. FYI that is the library that
>> makes ghci work.
>>
>> On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle
>> wrote:
>>
>>> I wrote a program first in Windows, where it works as expected, and now
>>> I'm using it in OS X and getting undesired behavior.
>>>
>>> It reads lines from the terminal using the getLine function. In Windows
>>> (DOS, actually) the up and down arrows can be used to choose previously
>>> entered lines. However, this does not work in bash in OS X.
>>>
>>> What do I need to get the history available via the arrow keys?
>>>
>>> D
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From toad3k at gmail.com Mon Aug 1 12:43:14 2016
From: toad3k at gmail.com (David McBride)
Date: Mon, 1 Aug 2016 08:43:14 -0400
Subject: [Haskell-beginners] reading lines with history from bash
terminal in OS X
In-Reply-To:
References:
Message-ID:
MonadIO m => MonadIO (InputT m)
MonadException m => MonadException (InputT m)
MonadIO means you have access to liftIO. liftIO . evaluate . force $
mycode.
MonadException means that you have access to haskeline's exception catching
mechanisms.
In System.Console.Haskeline.MonadException, you have the catch, catches,
and handle functions which will allow you to catch IO exceptions (in
combination with liftIO), and also a bracket which will just let you do
arbitrary IO actions and clean up when you are done (or hit an exception).
>let mycode = undefined :: Handle -> IO () -- example code
runInputT _ (bracket (liftIO $ openFile "blah" ReadMode) (liftIO . hClose)
(\fp -> liftIO . mycode $ fp))
Another way to use it might be
runInputT _ (liftIO $ mycode _) `catches` [Handler iohandler, Handler
anotherhandler]
where
iohandler :: IOException -> IO ()
iohandler e = putStrLn "got io exception" >> return ()
Exceptions are always a pain, and so are transformers, but you get used to
them.
On Mon, Aug 1, 2016 at 4:06 AM, Dennis Raddle
wrote:
> I'm looking over haskeline. It looks like I have to modify some of my code
> that is in the IO monad right now. I use 'evaluate' in several places, and
> also 'evaluate $ force', to make sure that IO exceptions are encountered
> where I can catch them. Can I use 'evaluate' with InputT? I'm muddled
> headed about what to do. I guess I would lift 'evaluate' into the inner
> monad? I am not sure what those words mean. How would I catch IO exceptions?
>
> On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle
> wrote:
>
>> Thanks. I'll install haskeline
>>
>> On Thu, Jul 28, 2016 at 5:05 PM, David McBride wrote:
>>
>>> You will have to use the haskeline library. FYI that is the library
>>> that makes ghci work.
>>>
>>> On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle
>>> wrote:
>>>
>>>> I wrote a program first in Windows, where it works as expected, and now
>>>> I'm using it in OS X and getting undesired behavior.
>>>>
>>>> It reads lines from the terminal using the getLine function. In Windows
>>>> (DOS, actually) the up and down arrows can be used to choose previously
>>>> entered lines. However, this does not work in bash in OS X.
>>>>
>>>> What do I need to get the history available via the arrow keys?
>>>>
>>>> D
>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From dennis.raddle at gmail.com Tue Aug 2 19:24:31 2016
From: dennis.raddle at gmail.com (Dennis Raddle)
Date: Tue, 2 Aug 2016 12:24:31 -0700
Subject: [Haskell-beginners] reading lines with history from bash
terminal in OS X
In-Reply-To:
References:
Message-ID:
Thanks. I will study this.
On Mon, Aug 1, 2016 at 5:43 AM, David McBride wrote:
> MonadIO m => MonadIO (InputT m)
> MonadException m => MonadException (InputT m)
>
> MonadIO means you have access to liftIO. liftIO . evaluate . force $
> mycode.
> MonadException means that you have access to haskeline's exception
> catching mechanisms.
>
> In System.Console.Haskeline.MonadException, you have the catch, catches,
> and handle functions which will allow you to catch IO exceptions (in
> combination with liftIO), and also a bracket which will just let you do
> arbitrary IO actions and clean up when you are done (or hit an exception).
>
> >let mycode = undefined :: Handle -> IO () -- example code
>
> runInputT _ (bracket (liftIO $ openFile "blah" ReadMode) (liftIO . hClose)
> (\fp -> liftIO . mycode $ fp))
>
> Another way to use it might be
>
> runInputT _ (liftIO $ mycode _) `catches` [Handler iohandler, Handler
> anotherhandler]
> where
> iohandler :: IOException -> IO ()
> iohandler e = putStrLn "got io exception" >> return ()
>
> Exceptions are always a pain, and so are transformers, but you get used to
> them.
>
> On Mon, Aug 1, 2016 at 4:06 AM, Dennis Raddle
> wrote:
>
>> I'm looking over haskeline. It looks like I have to modify some of my
>> code that is in the IO monad right now. I use 'evaluate' in several places,
>> and also 'evaluate $ force', to make sure that IO exceptions are
>> encountered where I can catch them. Can I use 'evaluate' with InputT? I'm
>> muddled headed about what to do. I guess I would lift 'evaluate' into the
>> inner monad? I am not sure what those words mean. How would I catch IO
>> exceptions?
>>
>> On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle
>> wrote:
>>
>>> Thanks. I'll install haskeline
>>>
>>> On Thu, Jul 28, 2016 at 5:05 PM, David McBride wrote:
>>>
>>>> You will have to use the haskeline library. FYI that is the library
>>>> that makes ghci work.
>>>>
>>>> On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle >>> > wrote:
>>>>
>>>>> I wrote a program first in Windows, where it works as expected, and
>>>>> now I'm using it in OS X and getting undesired behavior.
>>>>>
>>>>> It reads lines from the terminal using the getLine function. In
>>>>> Windows (DOS, actually) the up and down arrows can be used to choose
>>>>> previously entered lines. However, this does not work in bash in OS X.
>>>>>
>>>>> What do I need to get the history available via the arrow keys?
>>>>>
>>>>> D
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Beginners mailing list
>>>>> Beginners at haskell.org
>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From dan at dp.id.au Thu Aug 4 14:26:17 2016
From: dan at dp.id.au (Dan Phillips)
Date: Fri, 5 Aug 2016 00:26:17 +1000
Subject: [Haskell-beginners] import Control.Lens.Tutorial
Message-ID:
Hi all
I'm trying to follow this tutorial about lenses:
https://hackage.haskell.org/package/lens-tutorial-1.0.1/docs/Control-Lens-Tutorial.html
Right at the top of the tutorial,it says do this in ghci:
import Control.Lens.Tutorial
I tried that, but I got an error: "Could not find module
`Control.Lens.Tutorial'"
So I tried this:
D:\Sync\src\tutorials> stack install lens-tutorial
Run from outside a project, using implicit global project config
Using resolver: lts-6.9 from implicit global project's config file:
C:\Users\dan\AppData\Roaming\stack\global-project\stack.yaml
lens-tutorial-1.0.1: download
lens-tutorial-1.0.1: configure
lens-tutorial-1.0.1: build
lens-tutorial-1.0.1: copy/register
I'm not exactly sure what that did, but it looked promising. However, I
still get the same error in ghci as before when I do the import.
My question is, what do I need to do to get the import statement working in
ghci so I can follow the tutorial? I would be grateful for any guidance.
Thanks.
Regards
Dan Phillips
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From frefreak.zxy at gmail.com Thu Aug 4 14:32:59 2016
From: frefreak.zxy at gmail.com (adv_zxy)
Date: Thu, 04 Aug 2016 14:32:59 +0000
Subject: [Haskell-beginners] import Control.Lens.Tutorial
In-Reply-To:
References:
Message-ID:
Have you tried 'stack exec -- ghci'? This way ghci should be able to find
the packages stack installed.
On Thu, Aug 4, 2016, 10:27 PM Dan Phillips wrote:
> Hi all
>
> I'm trying to follow this tutorial about lenses:
>
>
> https://hackage.haskell.org/package/lens-tutorial-1.0.1/docs/Control-Lens-Tutorial.html
>
>
> Right at the top of the tutorial,it says do this in ghci:
>
> import Control.Lens.Tutorial
>
>
> I tried that, but I got an error: "Could not find module
> `Control.Lens.Tutorial'"
>
> So I tried this:
>
> D:\Sync\src\tutorials> stack install lens-tutorial
> Run from outside a project, using implicit global project config
> Using resolver: lts-6.9 from implicit global project's config file:
> C:\Users\dan\AppData\Roaming\stack\global-project\stack.yaml
> lens-tutorial-1.0.1: download
> lens-tutorial-1.0.1: configure
> lens-tutorial-1.0.1: build
> lens-tutorial-1.0.1: copy/register
>
> I'm not exactly sure what that did, but it looked promising. However, I
> still get the same error in ghci as before when I do the import.
>
> My question is, what do I need to do to get the import statement working
> in ghci so I can follow the tutorial? I would be grateful for any guidance.
> Thanks.
>
> Regards
> Dan Phillips
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Xiangyu Zhu
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From dan at dp.id.au Thu Aug 4 14:41:35 2016
From: dan at dp.id.au (Dan Phillips)
Date: Fri, 5 Aug 2016 00:41:35 +1000
Subject: [Haskell-beginners] import Control.Lens.Tutorial
In-Reply-To:
References:
Message-ID:
Awesome. That works. Thanks a lot.
2016-08-05 0:32 GMT+10:00 adv_zxy :
> Have you tried 'stack exec -- ghci'? This way ghci should be able to find
> the packages stack installed.
>
> On Thu, Aug 4, 2016, 10:27 PM Dan Phillips wrote:
>
>> Hi all
>>
>> I'm trying to follow this tutorial about lenses:
>>
>> https://hackage.haskell.org/package/lens-tutorial-1.0.1/
>> docs/Control-Lens-Tutorial.html
>>
>>
>> Right at the top of the tutorial,it says do this in ghci:
>>
>> import Control.Lens.Tutorial
>>
>>
>> I tried that, but I got an error: "Could not find module
>> `Control.Lens.Tutorial'"
>>
>> So I tried this:
>>
>> D:\Sync\src\tutorials> stack install lens-tutorial
>> Run from outside a project, using implicit global project config
>> Using resolver: lts-6.9 from implicit global project's config file:
>> C:\Users\dan\AppData\Roaming\stack\global-project\stack.yaml
>> lens-tutorial-1.0.1: download
>> lens-tutorial-1.0.1: configure
>> lens-tutorial-1.0.1: build
>> lens-tutorial-1.0.1: copy/register
>>
>> I'm not exactly sure what that did, but it looked promising. However, I
>> still get the same error in ghci as before when I do the import.
>>
>> My question is, what do I need to do to get the import statement working
>> in ghci so I can follow the tutorial? I would be grateful for any guidance.
>> Thanks.
>>
>> Regards
>> Dan Phillips
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> --
>
> Xiangyu Zhu
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From martin.drautzburg at web.de Sat Aug 6 08:03:17 2016
From: martin.drautzburg at web.de (martin)
Date: Sat, 6 Aug 2016 10:03:17 +0200
Subject: [Haskell-beginners] My Continuation doesn't typecheck
Message-ID: <57A599C5.2030208@web.de>
Hello all,
in order to gain some intuition about continuations, I tried the following:
-- two functions accepting a continuation
f1 :: Int -> (Integer->r) -> r
f1 a c = c $ fromIntegral (a+1)
f2 :: Integer -> (String -> r) -> r
f2 b c = c $ show b
-- combine the two functions into a single one
run1 :: Int -> (String -> r) -> r
run1 a = f1 a f2
-- *Main> run1 9 id
-- "10"
So far so good.
Then I tried to write a general combinator, which does not have f1 and f2 hardcoded:
combine a f g = f a g
-- This also works
-- *Main> combine 9 f1 f2 id
-- "10"
What confuses me is the the type of combine. I thought it should be
combine :: Int ->
(Int -> (Integer->r) -> r) -> -- f1
(Integer -> (String -> r) -> r) -> -- f2
((String -> r) -> r)
but that doesn't typecheck:
Couldn't match expected type ‘(String -> r) -> r’
with actual type ‘r’
Can you tell me where I am making a mistake?
From toad3k at gmail.com Sat Aug 6 17:01:00 2016
From: toad3k at gmail.com (David McBride)
Date: Sat, 6 Aug 2016 13:01:00 -0400
Subject: [Haskell-beginners] My Continuation doesn't typecheck
In-Reply-To: <57A599C5.2030208@web.de>
References: <57A599C5.2030208@web.de>
Message-ID:
The only way to do this is to do it step by step.
:t combine
combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t
>:t combine 9
combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t
>:t f1
f1 :: Int -> (Integer -> r) -> r
>:t combine 9 f1
combine 9 f1 :: (Integer -> t) -> t
>:t f2
f2 :: Integer -> (String -> r) -> r
>:t combine 9 f1 f2
combine 9 f1 f2 :: (String -> r) -> r
At some point the t2 in combine becomes a function, which causes the rest
of the type to change. I feel like combine was meant to be something else,
f (g a) or g (f a) or something else, but I'm not sure what.
On Sat, Aug 6, 2016 at 4:03 AM, martin wrote:
> Hello all,
>
> in order to gain some intuition about continuations, I tried the following:
>
> -- two functions accepting a continuation
>
> f1 :: Int -> (Integer->r) -> r
> f1 a c = c $ fromIntegral (a+1)
>
> f2 :: Integer -> (String -> r) -> r
> f2 b c = c $ show b
>
> -- combine the two functions into a single one
>
> run1 :: Int -> (String -> r) -> r
> run1 a = f1 a f2
>
>
> -- *Main> run1 9 id
> -- "10"
>
> So far so good.
>
>
> Then I tried to write a general combinator, which does not have f1 and f2
> hardcoded:
>
> combine a f g = f a g
>
> -- This also works
>
> -- *Main> combine 9 f1 f2 id
> -- "10"
>
>
> What confuses me is the the type of combine. I thought it should be
>
> combine :: Int ->
> (Int -> (Integer->r) -> r) -> -- f1
> (Integer -> (String -> r) -> r) -> -- f2
> ((String -> r) -> r)
>
>
> but that doesn't typecheck:
>
> Couldn't match expected type ‘(String -> r) -> r’
> with actual type ‘r’
>
>
> Can you tell me where I am making a mistake?
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From martin.drautzburg at web.de Sun Aug 7 11:05:02 2016
From: martin.drautzburg at web.de (martin)
Date: Sun, 7 Aug 2016 13:05:02 +0200
Subject: [Haskell-beginners] My Continuation doesn't typecheck
In-Reply-To:
References: <57A599C5.2030208@web.de>
Message-ID: <57A715DE.7060107@web.de>
David,
I used your method of hardcoding some of the parameters to find the correct type of 'combine'. It is not at all what I
expected or wanted, but here it is:
combine :: Int -> (Int -> (Integer -> (String -> r) -> r) -> (String -> r) -> r -> String) ->
(Integer -> (String -> r) -> r) -> (String -> r) -> r -> String
Not sure what this is trying to tell me.
Am 08/06/2016 um 07:01 PM schrieb David McBride:
> The only way to do this is to do it step by step.
> :t combine
> combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t
>
>>:t combine 9
> combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t
>
>>:t f1
> f1 :: Int -> (Integer -> r) -> r
>>:t combine 9 f1
> combine 9 f1 :: (Integer -> t) -> t
>
>>:t f2
> f2 :: Integer -> (String -> r) -> r
>>:t combine 9 f1 f2
> combine 9 f1 f2 :: (String -> r) -> r
>
> At some point the t2 in combine becomes a function, which causes the rest of the type to change. I feel like combine
> was meant to be something else, f (g a) or g (f a) or something else, but I'm not sure what.
>
>
> On Sat, Aug 6, 2016 at 4:03 AM, martin > wrote:
>
> Hello all,
>
> in order to gain some intuition about continuations, I tried the following:
>
> -- two functions accepting a continuation
>
> f1 :: Int -> (Integer->r) -> r
> f1 a c = c $ fromIntegral (a+1)
>
> f2 :: Integer -> (String -> r) -> r
> f2 b c = c $ show b
>
> -- combine the two functions into a single one
>
> run1 :: Int -> (String -> r) -> r
> run1 a = f1 a f2
>
>
> -- *Main> run1 9 id
> -- "10"
>
> So far so good.
>
>
> Then I tried to write a general combinator, which does not have f1 and f2 hardcoded:
>
> combine a f g = f a g
>
> -- This also works
>
> -- *Main> combine 9 f1 f2 id
> -- "10"
>
>
> What confuses me is the the type of combine. I thought it should be
>
> combine :: Int ->
> (Int -> (Integer->r) -> r) -> -- f1
> (Integer -> (String -> r) -> r) -> -- f2
> ((String -> r) -> r)
>
>
> but that doesn't typecheck:
>
> Couldn't match expected type ‘(String -> r) -> r’
> with actual type ‘r’
>
>
> Can you tell me where I am making a mistake?
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
From imantc at gmail.com Sun Aug 7 11:45:54 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 13:45:54 +0200
Subject: [Haskell-beginners] Bool newtype
Message-ID:
for a Bool-like newtype:
newtype B = B Bool
, is there an easy way to use this newtype B in place of Bool?
e.g.
let b1 = B True
in if b1 then 1 else 0
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From mdorman at jaunder.io Sun Aug 7 12:35:49 2016
From: mdorman at jaunder.io (Michael Alan Dorman)
Date: Sun, 07 Aug 2016 08:35:49 -0400
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
(Imants Cekusins's message of "Sun, 7 Aug 2016 13:45:54 +0200")
References:
Message-ID: <87mvkog3iy.fsf@jaunder.io>
Imants Cekusins writes:
> for a Bool-like newtype:
>
> newtype B = B Bool
>
> , is there an easy way to use this newtype B in place of Bool?
>
> e.g.
>
> let b1 = B True
> in if b1 then 1 else 0
>
> ?
Imants,
You can create a function that converts a B to a Bool:
toBool :: B -> Bool
toBool B b = b
And then use the result of applying that function to your variable:
let b1 = B True
in if toBool b1
then 1
else 0
To do anything like this automatically would seem to me to defeat the
purpose of having distinct types, which is to clearly articulate what
values are appropriate in particular contexts.
Mike.
From dima.samoz at gmail.com Sun Aug 7 12:38:05 2016
From: dima.samoz at gmail.com (Dmitrij Szamozvancev)
Date: Sun, 7 Aug 2016 13:38:05 +0100
Subject: [Haskell-beginners] Generalised symbolic expressions
Message-ID:
Hello all,
I'm learning about data types and type classes and tried implementing a
simple symbolic expression evaluator, but generalised for non-numeric data
types.
data GenExpr a = Atom a | Sum (GenExpr a) (GenExpr a) | Prod (GenExpr a)
(GenExpr a) | Neg (GenExpr a)
What I am hoping to do is write a general evaluation function which can
some GenExp expression and evaluate it. For example, giving it a GenExp
Integer would evaluate it according to normal arighmetic, GenExp Bool would
be evaluated using Boolean algebra etc. I've declared explicit type classes
for types that can be summed, multiplied and negated:
class HasSum a where (.+.) :: a -> a -> a
class HasProd a where (.*.) :: a -> a -> a
class HasNeg a where (.-) :: a -> a
instance HasSum Integer where (.+.) = (+)
instance HasProd Integer where (.*.) = (*)
instance HasNeg Integer where (.-) = negate
instance HasSum Bool where (.+.) = (||)
instance HasProd Bool where (.*.) = (&&)
instance HasNeg Bool where (.-) = not
-- Evaluate generalised expression
genEval :: (HasSum a, HasProd a, HasNeg a) => GenExpr a -> a
genEval (Atom a) = a
genEval (Sum ge1 ge2) = genEval ge1 .+. genEval ge2
genEval (Prod ge1 ge2) = genEval ge1 .*. genEval ge2
genEval (Neg ge) = (.-) $ genEval ge
However, I would like it to work with types that don't support all three
operations, e.g. natural numbers which don't have a negation operation or
strings that only have concatenation as addition:
instance HasSum Nat where (.+.) = (+)
instance HasProd Nat where (.*.) = (*)
instance HasSum String where (.+.) = (++)
But these wouldn't be suitable inputs for genEval because they don't fulfil
all three type constraints. The only solution I can think of is writing
separate genEvalNat and genEvalString functions, which kind of defeats the
purpose of the generalisation.
Is there a more elegant way to solve this problem?
Thank you in advance!
Dima
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From mdorman at jaunder.io Sun Aug 7 12:49:33 2016
From: mdorman at jaunder.io (Michael Alan Dorman)
Date: Sun, 07 Aug 2016 08:49:33 -0400
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
(Imants Cekusins's message of "Sun, 7 Aug 2016 13:45:54 +0200")
References:
Message-ID: <87popku4ki.fsf@aching.i-did-not-set--mail-host-address--so-tickle-me>
Imants Cekusins writes:
> for a Bool-like newtype:
>
> newtype B = B Bool
>
> , is there an easy way to use this newtype B in place of Bool?
>
> e.g.
>
> let b1 = B True
> in if b1 then 1 else 0
>
> ?
Imants,
You can create a function that converts a B to a Bool:
toBool :: B -> Bool
toBool B b = b
And then use the result of applying that function to your variable:
let b1 = B True
in if toBool b1
then 1
else 0
To do anything like this automatically would seem to me to defeat the
purpose of having distinct types, which is to clearly articulate what
values are appropriate in particular contexts.
Mike.
From imantc at gmail.com Sun Aug 7 13:13:26 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 15:13:26 +0200
Subject: [Haskell-beginners] Bool newtype
In-Reply-To: <87mvkog3iy.fsf@jaunder.io>
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
True: distinct types help. In this case a function expects a couple bool
args so the newtypes help ensure that correct args are passed in correct
order.
However when working with vals within a function, it may be handy to be
able to deduce bool from the newtype, at least to be used with if. This may
introduce complexity so not suggesting / requesting anything. Just
thought: something might be already available.
For example, num-like newtypes can be added, compared as are, without the
need to extract the num. Num newtypes conveniently can be derived with
"deriving".
A function you suggest is good and it works. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Sun Aug 7 13:41:10 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 15:41:10 +0200
Subject: [Haskell-beginners] Generalised symbolic expressions
In-Reply-To:
References:
Message-ID:
Dima,
is data GenExpr necessary?
would HasSum, HasProd, HasNeg classes & instances not be enough?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From marcin.jan.mrotek at gmail.com Sun Aug 7 14:49:39 2016
From: marcin.jan.mrotek at gmail.com (Marcin Mrotek)
Date: Sun, 7 Aug 2016 16:49:39 +0200
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
Hello,
That kind of a function can be also declared automatically, as in:
newtype B = B { toBool :: Bool }
Best regards,
Marcin Mrotek
From imantc at gmail.com Sun Aug 7 14:59:38 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 16:59:38 +0200
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
> newtype B = B { toBool :: Bool }
yep, this works well. toBool b1 is easy enough ;)
I wondered if there was an easy (with deriving etc) way to test B as it is.
If there isn't - no biggie.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Sun Aug 7 15:13:18 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 17:13:18 +0200
Subject: [Haskell-beginners] Generalised symbolic expressions
In-Reply-To:
References:
Message-ID:
> writing separate genEvalNat and genEvalString functions
.. here is another possibility:
data GenExpr_nat a = ...
data GenExpr_string a = ...
class GenEval exp a where
genEval ::exp a -> a
instance GenEval GenExpr_nat a where
...
instance GenEval GenExpr_string a where
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From ky3 at atamo.com Sun Aug 7 15:18:05 2016
From: ky3 at atamo.com (Kim-Ee Yeoh)
Date: Sun, 7 Aug 2016 22:18:05 +0700
Subject: [Haskell-beginners] My Continuation doesn't typecheck
In-Reply-To: <57A599C5.2030208@web.de>
References: <57A599C5.2030208@web.de>
Message-ID:
Have you heard of Djinn?
https://hackage.haskell.org/package/djinn
If you punch in the signature of the combine function you're looking for
(rewritten more usefully in Kleisli composition form):
(Int -> (Integer->r) -> r) ->
(Integer -> (String -> r) -> r) ->
(Int -> (String -> r) -> r)
you'll get your wish granted. Djinn will magically write combine for you.
It'll work even if you abstract over the concrete types of Int, Integer,
String.
You can popover to the haskell IRC to try it out on the djinn bot there if
installation is too much of a bother.
Best, Kim-Ee
On Saturday, August 6, 2016, martin wrote:
> Hello all,
>
> in order to gain some intuition about continuations, I tried the following:
>
> -- two functions accepting a continuation
>
> f1 :: Int -> (Integer->r) -> r
> f1 a c = c $ fromIntegral (a+1)
>
> f2 :: Integer -> (String -> r) -> r
> f2 b c = c $ show b
>
> -- combine the two functions into a single one
>
> run1 :: Int -> (String -> r) -> r
> run1 a = f1 a f2
>
>
> -- *Main> run1 9 id
> -- "10"
>
> So far so good.
>
>
> Then I tried to write a general combinator, which does not have f1 and f2
> hardcoded:
>
> combine a f g = f a g
>
> -- This also works
>
> -- *Main> combine 9 f1 f2 id
> -- "10"
>
>
> What confuses me is the the type of combine. I thought it should be
>
> combine :: Int ->
> (Int -> (Integer->r) -> r) -> -- f1
> (Integer -> (String -> r) -> r) -> -- f2
> ((String -> r) -> r)
>
>
> but that doesn't typecheck:
>
> Couldn't match expected type ‘(String -> r) -> r’
> with actual type ‘r’
>
>
> Can you tell me where I am making a mistake?
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From tanuki at gmail.com Sun Aug 7 20:48:24 2016
From: tanuki at gmail.com (Theodore Lief Gannon)
Date: Sun, 7 Aug 2016 13:48:24 -0700
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
As-is, no. As Michael said, that would defeat the purpose of a newtype.
However, there is a generic way: all newtypes are given instances of
Coercible, so instead of individual unwrap functions you can use coerce
from Data.Coerce.
On Aug 7, 2016 7:59 AM, "Imants Cekusins" wrote:
> > newtype B = B { toBool :: Bool }
>
> yep, this works well. toBool b1 is easy enough ;)
>
> I wondered if there was an easy (with deriving etc) way to test B as it
> is. If there isn't - no biggie.
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Sun Aug 7 21:12:26 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 23:12:26 +0200
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
Thank you Theodore.
> Data.Coerce
Could you hint the name of the package, please? Does it coerce safely?
If Coercible does not type check, another option could be to define a class
and a function that works similar to if statement, constrained to instances
of this class.
class Newtype_base nt base where
base_t::nt -> base
if_::Newtype_base nt Bool =>
nt -> then -> else
Standard if is clearer of course but with a few newtypes being passed
around, this may save some key strokes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Sun Aug 7 21:15:43 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 23:15:43 +0200
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
... this may be correct:
if_::Newtype_base nt Bool =>
nt -> result -> result -> result
if_ if0 then0 else0 = ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Sun Aug 7 21:47:15 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 7 Aug 2016 23:47:15 +0200
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
found it:
https://wiki.haskell.org/GHC/Coercible
yep, it type checks.
Ta
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From chak at justtesting.org Mon Aug 8 04:11:09 2016
From: chak at justtesting.org (Manuel M T Chakravarty)
Date: Mon, 8 Aug 2016 14:11:09 +1000
Subject: [Haskell-beginners] Learning Haskell: More About Algebraic Data
Types
Message-ID: <94290869-E4BB-4C82-A511-3C718A0ACBC6@justtesting.org>
We just published a new chapter in our online Haskell tutorial ”Learning Haskell”:
http://learn.hfm.io
This seventh chapter expands on algebraic data types by discussing parametric & recursive data types. It also includes a small graphics library to graphically render binary tries as you construct and manipulate them.
Happy Learning!
Manuel
From alexander at plaimi.net Mon Aug 8 09:36:19 2016
From: alexander at plaimi.net (Alexander Berntsen)
Date: Mon, 8 Aug 2016 11:36:19 +0200
Subject: [Haskell-beginners] reading lines with history from bash
terminal in OS X
In-Reply-To:
References:
Message-ID: <57A85293.5000806@plaimi.net>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
You can just run your program via the GNU readline wrapper.
- --
Alexander
alexander at plaimi.net
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCgAGBQJXqFKTAAoJENQqWdRUGk8Bw9kQAJt69W6tx5nAuBLEBN3Dxbgn
ywd2vnlHxAjM5mwhO5fesjHVQrn7KmMNnKCwAZoheN5CzQ+FTloph5b1N5vz8+PW
ScbOXkO0DllsEEGm+xVbizMtNBd/jQcTZCfne88L+pN17iB8Tq38BO/Z0wGdHBa6
9wc5zVA8WYIp3Rz6JenCbMMNdkvlJkGPLtFj4Dc4HpjUUf0shkYBD2FLY/+KdJmy
TS8rpa8pmUf7iLJtjx08/aq3mlOnUneV1MLMU48YAHSxIirumiN1FqZob9xsJxGy
13oxevngEBfNCfNNHoHFCWxh7ouxvpLKszmwTb25Ts7aOyqPMXifTTrZhL7ZYTad
emy/cmbIZu430JbeNTti0gZiqD6ZxjEDXxlFIrAIr/lqoIUghqabKcu2ddq/8pqD
VSwymoxTCvJ0sZgpxnCRFwoilZh47W9wPISrIdAjgJTSpGpInzVteXfJi0t49B/G
wKUruCO2uZjeznU5iBTPRKBKUab4WhbvF9bJeSPk+tHlNHlqFd3uEFymyB8lHFAu
+d/89LUFz+wZXplHgDX4Qd/4SBhUILOdMUr60tCszWuI/HpxoZrLWVtIbZJ5Exvn
k6L803FPU6/M1Z2GgB5lRSNOUDm2zJdNK/hpUxXaBQpFVVc/6hK+1WLMS7jZ/hiH
eaVanrvlJ6m/kdRRMF0L
=0Z0J
-----END PGP SIGNATURE-----
From martin.drautzburg at web.de Mon Aug 8 14:40:00 2016
From: martin.drautzburg at web.de (martin)
Date: Mon, 8 Aug 2016 16:40:00 +0200
Subject: [Haskell-beginners] My Continuation doesn't typecheck
In-Reply-To:
References: <57A599C5.2030208@web.de>
Message-ID: <57A899C0.104@web.de>
Am 08/07/2016 um 05:18 PM schrieb Kim-Ee Yeoh:
> Have you heard of Djinn?
>
> https://hackage.haskell.org/package/djinn
>
> If you punch in the signature of the combine function you're looking for (rewritten more usefully in Kleisli composition
> form):
>
> (Int -> (Integer->r) -> r) ->
> (Integer -> (String -> r) -> r) ->
> (Int -> (String -> r) -> r)
>
Thanks for pointing out Djinn, but I want to understand. And there are a number of things I don't understand. Maybe you
can help me out:
(1) what is the "more useful Kleisli composition" and what would be "less useful" ?
(2) I was hoping my experiments would eventually make the Cont monad appear and I originally even named my combinator
'bind' instead of 'combine'. My hope was fueled by the observation that
combine a f g = f a g
works with
f substitued with f1 :: Int -> (Integer->r) -> r and
g substitued with f2 :: Integer -> (String -> r) -> r
As a next step I would have wrapped (b->r) -> r in a newtype C r b and my functions f1 and f2 would have had the types
f1 :: Int -> C r Integer
f2 :: Integer -> C r String
Now my 'combine' function seems to be different from 'bind' (>>=). It also just too simple to be true.
Somwhere I am making a fundamental mistake, but I cannot quite see it.
From ky3 at atamo.com Mon Aug 8 15:32:38 2016
From: ky3 at atamo.com (Kim-Ee Yeoh)
Date: Mon, 8 Aug 2016 22:32:38 +0700
Subject: [Haskell-beginners] My Continuation doesn't typecheck
In-Reply-To: <57A899C0.104@web.de>
References: <57A599C5.2030208@web.de>
<57A899C0.104@web.de>
Message-ID:
>
> (1) what is the "more useful Kleisli composition" and what would be "less
> useful" ?
This type signature
(Int -> (Integer->r) -> r) ->
(Integer -> (String -> r) -> r) ->
(Int -> (String -> r) -> r)
is the Cont monad instantiation of
(>=>) :: Monad
m => (a -> m b) -> (b -> m c) -> a -> m c
See
http://hackage.haskell.org/package/base-4.9.0.0/docs/
Control-Monad.html#v:-62--61--62-
Being more uniform, this signature is more useful than the one you had
earlier worked with:
combine :: Int ->
(Int -> (Integer->r) -> r) -> -- f1
(Integer -> (String -> r) -> r) -> -- f2
((String -> r) -> r)
> Now my 'combine' function seems to be different from 'bind' (>>=). It
also just too simple to be true.
You got Kleisli composition, although not monadic bind. That's still a win
of sorts.
Best, Kim-Ee Yeoh
On Monday, August 8, 2016, martin > wrote:
> Am 08/07/2016 um 05:18 PM schrieb Kim-Ee Yeoh:
> > Have you heard of Djinn?
> >
> > https://hackage.haskell.org/package/djinn
> >
> > If you punch in the signature of the combine function you're looking for
> (rewritten more usefully in Kleisli composition
> > form):
> >
> > (Int -> (Integer->r) -> r) ->
> > (Integer -> (String -> r) -> r) ->
> > (Int -> (String -> r) -> r)
> >
>
> Thanks for pointing out Djinn, but I want to understand. And there are a
> number of things I don't understand. Maybe you
> can help me out:
>
> (1) what is the "more useful Kleisli composition" and what would be "less
> useful" ?
> (2) I was hoping my experiments would eventually make the Cont monad
> appear and I originally even named my combinator
> 'bind' instead of 'combine'. My hope was fueled by the observation that
>
>
> combine a f g = f a g
>
> works with
> f substitued with f1 :: Int -> (Integer->r) -> r and
> g substitued with f2 :: Integer -> (String -> r) -> r
>
> As a next step I would have wrapped (b->r) -> r in a newtype C r b and my
> functions f1 and f2 would have had the types
>
> f1 :: Int -> C r Integer
> f2 :: Integer -> C r String
>
> Now my 'combine' function seems to be different from 'bind' (>>=). It also
> just too simple to be true.
>
> Somwhere I am making a fundamental mistake, but I cannot quite see it.
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From menemenetekelupharsin at gmx.com Sat Aug 13 18:37:57 2016
From: menemenetekelupharsin at gmx.com (George Taylor)
Date: Sat, 13 Aug 2016 20:37:57 +0200
Subject: [Haskell-beginners] Problem getting haskell-mode working with emacs
on windows
Message-ID:
Hello,
Environment: Win7 32bit, Emacs 24.5.1, ghci 7.8.3
I have had Haskell working with Windows 7 and emacs previously, but have had issues, and am attempting to get everything working again. Problems.
I searched for "Install Haskell Emacs", and found a link to the page
https://wiki.haskell.org/Emacs/Installing_haskell-mode
But this page was blanked on 11 April 2016, with no information as to where to go.
I looked at the previous version of the page, and it said to "place the basic mode haskell-mode.el and the modules you want to use in [a suitable directory, I used "~/haskell-extensions"], add the following command to your init file (~/.emacs):
(load "~/lib/emacs/haskell-site-file")"
I did the above (but just with haskell-mode.el) and launched emacs, and got a message:
"File error: Cannot open load file, no such file or directory, ~/haskell-extensions/haskell-site-file"
in emacs, as an experiment, I did M-x Load file: C:\home/haskell-extensions/haskell-mode.el
And got the message "Cannot open load file: no such file or directory, haskell-customize"
I downloaded haskell-customize.el and placed it in ~/haskell-extensions, and tried again, but no joy.
Questions:
0. Is haskell-mode depracated? It no longer seems to be available at MELPA.
1. Why was the page "https://wiki.haskell.org/Emacs/Installing_haskell-mode" blanked?
2. Is a similar, current set of instructions available?
3. Should I be able to load haskell-mode using M-x load-file? If so, what other .el (or other) files are required, and where should they be placed?
4. Is there a dissimilar set of instructions available?
Any help will win thousands in prizes.
From rein.henrichs at gmail.com Sat Aug 13 20:27:22 2016
From: rein.henrichs at gmail.com (Rein Henrichs)
Date: Sat, 13 Aug 2016 20:27:22 +0000
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
Consider replacing your bools with meaningful sum types, which avoids this
issue, prevents boolean blindness, and makes your code more
self-documenting.
For example, instead of newtype SwitchsState = SwitchState Bool, data
SwitchState = On | Off
On Sun, Aug 7, 2016 at 2:47 PM Imants Cekusins wrote:
> found it:
>
> https://wiki.haskell.org/GHC/Coercible
>
> yep, it type checks.
>
> Ta
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Sun Aug 14 06:06:26 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Sun, 14 Aug 2016 08:06:26 +0200
Subject: [Haskell-beginners] Bool newtype
In-Reply-To:
References:
<87mvkog3iy.fsf@jaunder.io>
Message-ID:
> data SwitchState = On | Off
yep, this is clearer than newtype Bool. "If"s may be replaced with "case",
and code becomes shorter.
Nice one.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From jonas.beal at novadiscovery.com Wed Aug 17 08:40:07 2016
From: jonas.beal at novadiscovery.com (=?UTF-8?Q?Jonas_B=C3=A9al?=)
Date: Wed, 17 Aug 2016 10:40:07 +0200
Subject: [Haskell-beginners] Automatic Differentiation
Message-ID:
Hello,
I have some questions about the Automatic Differentiation package in
Haskell (https://hackage.haskell.org/package/ad-4.3.2.1/docs/Numeric-AD.html
)
I need to compute the jacobian with that method and I have a type problem,
here a simplified example in order to focus on the error:
According to documentation I need to write "*jacobian function values*". So
I built the input *function. *Please notice this is important for me that
my function may depend on an external parameter (named factor here)
testFunctionForJacobian :: Fractional a => a -> [a] -> [a]
testFunctionForJacobian factor inputs = [(sum inputs) * factor]
Then, using *jacobian* function of Numeric.AD in terminal, as a test, it
works perfectly
>jacobian (testFunctionForJacobian 2) [1,2]
< [[2.0,2.0]]
No apparent type problem here
> :t (testFunctionForJacobian 2)
(testFunctionForJacobian 2) :: Fractional a => [a] -> [a]
But, I would like to insert that in a bigger function computing the jacobian
testJacobian :: Fractional a => a -> [a] -> [[a]]
testJacobian factor inputs = jacobian (testFunctionForJacobian factor)
inputs
This time it generates an error message about *factor*
Couldn't match expected type ‘Numeric.AD.Internal.Reverse.Reverse
s a’ with actual type ‘a’
‘a’ is a rigid type variable bound by the type signature for
testJacobian :: Fractional a => a -> [a] -> [[a]] s a’
All in all, my type seems implicitly correct in the terminal example but I
did not manage to write it explicitly in my function.
Here the *jacobian* function signature to help you answer me:
--
Jonas Béal
--
*This message is intended only for the personal and confidential use of the
designated recipient(s) named above. If you are not the intended recipient
of this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited. Email
transmission cannot be guaranteed to be secure or error-free. Therefore, we
do not represent that this information is complete or accurate and it
should not be relied upon as such. All information is subject to change
without notice.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From jonas.beal at novadiscovery.com Wed Aug 17 08:41:06 2016
From: jonas.beal at novadiscovery.com (=?UTF-8?Q?Jonas_B=C3=A9al?=)
Date: Wed, 17 Aug 2016 10:41:06 +0200
Subject: [Haskell-beginners] Automatic Differentiation
In-Reply-To:
References:
Message-ID:
jacobian :: (Traversable
f, Functor
g, Num
a)
=> (forall s. Reifies
s Tape
=>
f (Reverse
s
a) -> g (Reverse
s
a)) -> f a -> g (f a)
Thanks a lot for your help
Jonas BÉAL
On 17 August 2016 at 10:40, Jonas Béal wrote:
> Hello,
>
> I have some questions about the Automatic Differentiation package in
> Haskell (https://hackage.haskell.org/package/ad-4.3.2.1/docs/Numeric
> -AD.html)
> I need to compute the jacobian with that method and I have a type problem,
> here a simplified example in order to focus on the error:
>
> According to documentation I need to write "*jacobian function values*".
> So I built the input *function. *Please notice this is important for me
> that my function may depend on an external parameter (named factor here)
> testFunctionForJacobian :: Fractional a => a -> [a] -> [a]
> testFunctionForJacobian factor inputs = [(sum inputs) * factor]
>
> Then, using *jacobian* function of Numeric.AD in terminal, as a test, it
> works perfectly
> >jacobian (testFunctionForJacobian 2) [1,2]
> < [[2.0,2.0]]
>
> No apparent type problem here
> > :t (testFunctionForJacobian 2)
> (testFunctionForJacobian 2) :: Fractional a => [a] -> [a]
>
> But, I would like to insert that in a bigger function computing the
> jacobian
> testJacobian :: Fractional a => a -> [a] -> [[a]]
> testJacobian factor inputs = jacobian (testFunctionForJacobian factor)
> inputs
>
> This time it generates an error message about *factor*
> Couldn't match expected type ‘Numeric.AD.Internal.Reverse.Reverse
> s a’ with actual type ‘a’
> ‘a’ is a rigid type variable bound by the type signature for
> testJacobian :: Fractional a => a -> [a] -> [[a]] s a’
>
> All in all, my type seems implicitly correct in the terminal example but I
> did not manage to write it explicitly in my function.
>
> Here the *jacobian* function signature to help you answer me:
>
>
>
>
>
>
> --
> Jonas Béal
>
--
Jonas Béal
R&D Scientist Intern
jonas.beal at novadiscovery.com
Novadiscovery
The Effect Model Co.
www.novadiscovery.com
+33 9 72 53 13 00
Bioparc Laënnec, 60 avenue Rockefeller, 69008 Lyon
--
*This message is intended only for the personal and confidential use of the
designated recipient(s) named above. If you are not the intended recipient
of this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited. Email
transmission cannot be guaranteed to be secure or error-free. Therefore, we
do not represent that this information is complete or accurate and it
should not be relied upon as such. All information is subject to change
without notice.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From xiut.xu at gmail.com Sun Aug 21 22:05:52 2016
From: xiut.xu at gmail.com (xu xiut)
Date: Sun, 21 Aug 2016 16:05:52 -0600
Subject: [Haskell-beginners] help writing a simple api which queries for a
resource and displays this info
Message-ID:
Hello, I am wanting to store something in a database, then retrieve it.
That is my entire ambition for the day.
Technologies chosen:
spock:
https://github.com/agrafix/Spock
rethinkdb driver:
https://github.com/AtnNn/haskell-rethinkdb
I chose to go with Rethinkdb, but i'm open to using Postgresql.
If someone requests for /companies, I want to list all the companies in the
"companies" table.
```
-- ghci
λ> companies <- run h $ table "companies" :: IO [Datum]
λ> companies
[{"name":"tesla","id":"7781ee7e-1e43-4608-bb96-fe10cac3b53a"}]
λ> firstCompany <- run h $ table "companies" ! "name" :: IO [Datum]
λ> firstCompany
["tesla"]
λ> :info Datum
data Datum
= Null
| Bool Bool
| String Text
| Number Double
| Array Database.RethinkDB.Datum.Array
| Object Database.RethinkDB.Datum.Object
| Time time-1.5.0.1:Data.Time.LocalTime.LocalTime.ZonedTime
| Point LonLat
| Line GeoLine
| Polygon GeoPolygon
| Binary bytestring-0.10.6.0:Data.ByteString.Internal.ByteString
-- Defined in ‘Database.RethinkDB.Datum’
instance Eq Datum -- Defined in ‘Database.RethinkDB.Datum’
instance Ord Datum -- Defined in ‘Database.RethinkDB.Datum’
instance Show Datum -- Defined in ‘Database.RethinkDB.Datum’
instance Expr Datum -- Defined in ‘Database.RethinkDB.ReQL’
instance Result Datum -- Defined in ‘Database.RethinkDB.Driver’
instance ToDatum Datum -- Defined in ‘Database.RethinkDB.Datum’
instance FromDatum Datum -- Defined in ‘Database.RethinkDB.Datum’
15:40 < lpaste> xuxu revised “investigating the Datum
data type”: “investigating the Datum data
type” at http://lpaste.net/179391
```
I don't know how to display the result.
>From Spock's readme, here's an example where I don't need to query the
database:
```
main =
runSpock 3000 $ spockT id $
do get "companies" $
text $ T.concat ["tesla", "google"]
```
How to convert that into something a little more practial where I do
utilize a db?
Here's what I have right now, but I'm sure it doesn't compile
```
{-# LANGUAGE OverloadedStrings #-}
import Web.Spock
import qualified Data.Text as T
import qualified Database.RethinkDB as R
import qualified Database.RethinkDB.NoClash
default (Datum, ReQL, String, Int, Double)
main :: IO ()
main =
-- 1. i don't know if the following line will work
let h = connect "localhost" 28015 Nothing in
runSpock 3000 $ spockT id $
-- 2. list all companies
do get "companies" $
text $ T.concat -- something
```
I don't exactly know how "text" works.
If I'm reading
https://github.com/agrafix/Spock/blob/1ee54503ad67f62af795a31772040f56f7ae08fd/Spock-core/src/Web/Spock/Core.hs#L55
correctly, spockT is using a reader monad. I don't know how it works with
the Text type, but I have a suspicion I need to convert Rethink's Datum
type into a Text type.
I would be absolutely thrilled if anyone is able to help with this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 10:01:08 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 12:01:08 +0200
Subject: [Haskell-beginners] type T' = T a b c
Message-ID:
*problem*:
given type T with a few parameters e.g.
T a b c
some functions where this type is passed to, are agnostic to a, b, c
i.e. accept T with any of a, b, c
processT::T a b c -> ()
when either number of these parameters or T change (c is dropped or d is
added: T a b c d), signatures of every function where T is passed to, need
to be updated.
*question*:
is this possible to specify type synonym T' so that it may be passed to
parameter (a,b,c) - agnostic functions so:
processT::T' -> ()
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 10:29:14 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 12:29:14 +0200
Subject: [Haskell-beginners] type T' = T a b c
In-Reply-To:
References:
Message-ID:
just came across this:
https://downloads.haskell.org/~ghc/7.0.3/docs/html/users_guide/data-type-extensions.html
this seems to work:
ExistentialQuantification
Rank2Types
type T' = forall a b. (T a b)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 11:32:15 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 13:32:15 +0200
Subject: [Haskell-beginners] type T' = T a b c
In-Reply-To:
References:
Message-ID:
T' and T a b seem to not mix well.
T' can not be passed to a function expecting T a b and vice versa
any suggestions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From toad3k at gmail.com Mon Aug 22 12:23:18 2016
From: toad3k at gmail.com (David McBride)
Date: Mon, 22 Aug 2016 08:23:18 -0400
Subject: [Haskell-beginners] type T' = T a b c
In-Reply-To:
References:
Message-ID:
If you want to have something that can ignore a variable, you can just fill
it in with (). T Int Char () (), then have a function :: T a b () () -> IO
(). You can clean it up a little by making type aliases. type T2 a b = T
a b () (), type T3 a b c = T a b c ().
On Mon, Aug 22, 2016 at 7:32 AM, Imants Cekusins wrote:
> T' and T a b seem to not mix well.
>
> T' can not be passed to a function expecting T a b and vice versa
>
> any suggestions?
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 12:40:52 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 14:40:52 +0200
Subject: [Haskell-beginners] type T' = T a b c
In-Reply-To:
References:
Message-ID:
David, this seem to work similar to forall...:
synonym is not compatible with T a b.
you see, I hope to mix synonym with original T a b in a chain of fun calls.
Some of the funs accept args like this:
fun1::T a b -> a -> out1
.. and others - like this:
fun2::T' -> out2
in both cases a and b are not set. However in fun1 I try to enforce type
'a' in the arg #2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From tanuki at gmail.com Mon Aug 22 12:45:46 2016
From: tanuki at gmail.com (Theodore Lief Gannon)
Date: Mon, 22 Aug 2016 05:45:46 -0700
Subject: [Haskell-beginners] type T' = T a b c
In-Reply-To:
References:
Message-ID:
Go in the other direction?
data T a b = T a b
type T2 a b c = T a (b, c)
type T3 a b c d = T a (b, c, d)
On Aug 22, 2016 5:40 AM, "Imants Cekusins" wrote:
> David, this seem to work similar to forall...:
>
> synonym is not compatible with T a b.
>
> you see, I hope to mix synonym with original T a b in a chain of fun
> calls.
>
> Some of the funs accept args like this:
> fun1::T a b -> a -> out1
>
> .. and others - like this:
> fun2::T' -> out2
>
> in both cases a and b are not set. However in fun1 I try to enforce type
> 'a' in the arg #2.
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 12:51:13 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 14:51:13 +0200
Subject: [Haskell-beginners] type T' = T a b c
In-Reply-To:
References:
Message-ID:
> data T a b = T a b
> type T2 a b c = T a (b, c)
how would this work if T were a record? say:
data T a b = T {
a::a,
b::b,
agnostic::Int
}
could we make a T' (no param) out of it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 12:56:39 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 14:56:39 +0200
Subject: [Haskell-beginners] type T' = T a b c
In-Reply-To:
References:
Message-ID:
ok this may be it:
data T a = T {
a::a,
common::Int
}
type T' a b = T (a,b)
# of record fields stays the same however we cram more data into the 'a'
field.
it surely works. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From 50295 at web.de Mon Aug 22 16:07:30 2016
From: 50295 at web.de (Olumide)
Date: Mon, 22 Aug 2016 17:07:30 +0100
Subject: [Haskell-beginners] Functions as Applicatives
Message-ID:
Hi List,
I'm struggling to relate the definition of a function as a function
instance Applicative ((->) r) where
pure x = (\_ -> x)
f <*> g = \x -> f x (g x)
with the following expression
ghci> :t (+) <$> (+3) <*> (*100)
(+) <$> (+3) <*> (*100) :: (Num a) => a -> a
ghci> (+) <$> (+3) <*> (*100) $ 5
508
From chapter 11 of LYH http://goo.gl/7kl2TM .
I understand the explanation in the book: "we're making a function that
will use + on the results of (+3) and (*100) and return that. To
demonstrate on a real example, when we did (+) <$> (+3) <*> (*100) $ 5,
the 5 first got applied to (+3) and (*100), resulting in 8 and 500.
Then, + gets called with 8 and 500, resulting in 508."
The problem is that I can't relate that explanation with the definition
of a function as an applicative; especially f <*> g = \x -> f x (g x) .
Is (g x) the second argument to f?
Regards,
- Olumide
From imantc at gmail.com Mon Aug 22 17:34:11 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 19:34:11 +0200
Subject: [Haskell-beginners] Functions as Applicatives
In-Reply-To:
References:
Message-ID:
Hello Ollumide,
this may help: it builds and runs anyway.
{-
instance Applicative ((->) r) where
pure x = (\_ -> x)
f <*> g = \x -> f x (g x)
with the following expression
ghci> :t (+) <$> (+3) <*> (*100)
(+) <$> (+3) <*> (*100) :: (Num a) => a -> a
ghci> (+) <$> (+3) <*> (*100) $ 5
508
-}
f::Num f => f -> f -> f
f = (+)
g::Num g => g -> g
g = (+ 3)
h::Num h => h -> h
h = (* 100)
fg::Num a => a -> a -> a
fg = f <$> g
{- fg a b = a + (b + 3)
fg a = \b -> a + (b + 3)
-}
fgh::Num a => a -> a
fgh = fg <*> h
{- fgh b = fg (b * 100)
fgh = \b -> fg (b * 100)
-}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 17:42:02 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 19:42:02 +0200
Subject: [Haskell-beginners] Functions as Applicatives
In-Reply-To:
References:
Message-ID:
fgh::Num a => a -> a
fgh = fg <*> h
{- fgh a = fg a (a * 100)
fgh = \a -> fg a (a * 100)
-}
, that is
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From imantc at gmail.com Mon Aug 22 18:13:30 2016
From: imantc at gmail.com (Imants Cekusins)
Date: Mon, 22 Aug 2016 20:13:30 +0200
Subject: [Haskell-beginners] Functions as Applicatives
In-Reply-To:
References:
Message-ID:
.. actually, I got fg wrong. Caught it by changing g to (/ ):
f::Fractional f => f -> f -> f
f = (+)
g::Fractional g => g -> g
g a = a / 2
h::Fractional h => h -> h
h = (* 10)
fg::Fractional a => a -> a -> a
fg = f <$> g
{- fg a b = (a / 2) + b
fg a = \b -> (a / 2) + b
-}
fgh::Fractional a => a -> a
fgh = fg <*> h
{- fgh a = fg a (a * 10)
fgh = \a -> fg a (a * 10)
-}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From rein.henrichs at gmail.com Mon Aug 22 21:14:19 2016
From: rein.henrichs at gmail.com (Rein Henrichs)
Date: Mon, 22 Aug 2016 21:14:19 +0000
Subject: [Haskell-beginners] Functions as Applicatives
In-Reply-To:
References:
Message-ID:
In f <*> g = \x -> f x (g x), g is the second argument to <*>. The result
of f <*> g is a function that takes an argument (x) and gives f x (g x). So
basically <*> combines the functions f and g in a particular way to give a
new function. In fact, it is the only way to combine them that type checks
(and doesn't use undefined or similar).
On Mon, Aug 22, 2016 at 11:13 AM Imants Cekusins wrote:
> .. actually, I got fg wrong. Caught it by changing g to (/ ):
>
>
> f::Fractional f => f -> f -> f
> f = (+)
>
> g::Fractional g => g -> g
> g a = a / 2
>
> h::Fractional h => h -> h
> h = (* 10)
>
>
> fg::Fractional a => a -> a -> a
> fg = f <$> g
> {- fg a b = (a / 2) + b
> fg a = \b -> (a / 2) + b
> -}
>
> fgh::Fractional a => a -> a
> fgh = fg <*> h
> {- fgh a = fg a (a * 10)
> fgh = \a -> fg a (a * 10)
> -}
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From 50295 at web.de Mon Aug 22 23:20:26 2016
From: 50295 at web.de (Olumide)
Date: Tue, 23 Aug 2016 00:20:26 +0100
Subject: [Haskell-beginners] Functions as Applicatives
In-Reply-To:
References: