Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Improve my lambda expressions (PATRICK BROWNE)
   2.  a way to check whether a file is actually being  written on
      (Silent Leaf)
   3. Re:  a way to check whether a file is actually    being written
      on (Silent Leaf)
   4. Re:  a way to check whether a file is actually being written
      on (Jona Ekenberg)


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

Message: 1
Date: Tue, 27 Jun 2017 17:35:11 +0100
From: PATRICK BROWNE <patrick.bro...@dit.ie>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Improve my lambda expressions
Message-ID:
        <cagflrke3vxonquvtgd8v9q4o6pg_orvledmfkb7jf5zjxzu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks for all your help.
I was unaware that there was a relation between let/where and lambdas.
Here is my effort to use a single lamda
md3 n = (\n -> (dist  (Point (4.0 + 0.5 * n) (4.0 - 0.5 * n)) (Point (n *
1.0) ( n * (-1.0))))) n

I imagine that this function could be written without lambdas, let, or
where.
Is it generally true the all/most functions could be written without
lambdas, let, or where?

Thanks,
Pat



On 26 June 2017 at 12:04, Frerich Raabe <ra...@froglogic.com> wrote:

> On 2017-06-26 11:38, PATRICK BROWNE wrote:
>
>> The code below provides a distance function that works for points and
>> moving point.
>> I am happy with the result, but I have a problem with the lambda
>> expressions.
>>
>
> [..]
>
> -- Sttic points
>> p1, p2 :: Point Float
>> p1 = Point 0.0 0.0
>> p2 = Point 4.0 4.0
>> d = dist p1 p2
>>
>> -- Moving points
>> mp1, mp2 :: Point Float
>> mp1x = (\t -> 4.0 + 0.5 * t)
>> mp1y = (\t -> 4.0 - 0.5 * t)
>> mp1 = Point (mp1x 2) (mp1y  2)
>> mp2x  = (\t -> 0.0 + 1.0 * t)
>> mp2y  = (\t -> 0.0 - 1.0 * t)
>> mp2 = Point (mp2x 2) (mp2y 2)
>> md = dist mp1 mp2
>>
>
> Maybe you could reduce the number of lambda expressions by extracting
> common logic. It seems to me that 'mp1' and 'mp2' are moved versions of the
> same point (2,2) except that they apply different functions to the
> coordinates. These functions follow a pattern (a factor is applied to the
> component and then an 'offset' is added).
>
> For instance, it might be worthwhile to define
>
>   movePoint :: Float -> Float -> Point -> Point
>   movePoint offset factor (Point x y) = Point (offset + factor * x)
> (offset - factor * y)
>
> ...such that you could then define
>
> md = let p = Point 2 2 in dist (movePoint 4 0.5 p) (movePoint 0 1 p)
>
> --
> Frerich Raabe - ra...@froglogic.com
> www.froglogic.com - Multi-Platform GUI Testing
>

-- 


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170627/d2f6c0eb/attachment-0001.html>

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

Message: 2
Date: Tue, 27 Jun 2017 21:42:03 +0200
From: Silent Leaf <silent.le...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] a way to check whether a file is actually
        being   written on
Message-ID:
        <cagfccjphrco8loear88jot+ghcadasvsqwfx5dccpsgy2j6...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

i created a small clone of dd in haskell. I made it so it only copies block
by block and only if there's any difference between each pair of blocks
from each file. the idea is to use this dd clone as backup system,
especially since my partitions are nearly full, so no real loss in copying
the whole things.

I'm wondering if there's any way to check if my program never ever writes
onto the target unless actually needed. obviously by reading the code i'd
say it does what i want, but we do make test cases rather than rely on what
we think the code does.

i can't run it with a target file that would be made read-only in the
filesys (and hope for an error for trying to write on it) since obviously i
need to open it in read-write right from the beginning, in case of actual
need of writing (as apparently i can't have two handles on the same file...
although maybe there's a way to change the mode of opening on the run? did
not find it in System.IO nor in Hoogle or Hayoo)

so if anyone has an idea, in or outside of haskell, that would be great!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170627/cd198728/attachment-0001.html>

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

Message: 3
Date: Tue, 27 Jun 2017 22:14:24 +0200
From: Silent Leaf <silent.le...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] a way to check whether a file is
        actually        being written on
Message-ID:
        <CAGFccjP6j=9G0fb86xF=2ygtqvekuvjwbf0xemsygfrqsow...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

by the way: dd has this option that says "in case of read error, do not
stop, continue". it's recomended to use it altho i never actually gotten
why.
my point is: how to handle any kind of read/write exception with my clone?
i used withBinaryFile which promised to close my handles no matter what,
which is great, but i don't feel much secured since i don't know how my
program would handle a bumpy ride or even if it would tell me anything... i
don't even know what would happen if it were cut in the middle, etc.

on this general topic, by the way, are there good resources for
system-programming with haskell? is it even manageable to do so rather than
use c-like (go, c++, etc) languages?

2017-06-27 21:42 GMT+02:00 Silent Leaf <silent.le...@gmail.com>:

> Hi,
>
> i created a small clone of dd in haskell. I made it so it only copies
> block by block and only if there's any difference between each pair of
> blocks from each file. the idea is to use this dd clone as backup system,
> especially since my partitions are nearly full, so no real loss in copying
> the whole things.
>
> I'm wondering if there's any way to check if my program never ever writes
> onto the target unless actually needed. obviously by reading the code i'd
> say it does what i want, but we do make test cases rather than rely on what
> we think the code does.
>
> i can't run it with a target file that would be made read-only in the
> filesys (and hope for an error for trying to write on it) since obviously i
> need to open it in read-write right from the beginning, in case of actual
> need of writing (as apparently i can't have two handles on the same file...
> although maybe there's a way to change the mode of opening on the run? did
> not find it in System.IO nor in Hoogle or Hayoo)
>
> so if anyone has an idea, in or outside of haskell, that would be great!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170627/ff6e89df/attachment-0001.html>

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

Message: 4
Date: Tue, 27 Jun 2017 22:42:53 +0200
From: Jona Ekenberg <saik...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] a way to check whether a file is
        actually being written on
Message-ID:
        <calveeuckvechzm_pg_6wbwu6thxsvkhg62zh4rz7-pdxt9g...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Den 27 juni 2017 9:47 em skrev "Silent Leaf" <silent.le...@gmail.com>:

Hi,

i created a small clone of dd in haskell. I made it so it only copies block
by block and only if there's any difference between each pair of blocks
from each file. the idea is to use this dd clone as backup system,
especially since my partitions are nearly full, so no real loss in copying
the whole things.

I'm wondering if there's any way to check if my program never ever writes
onto the target unless actually needed. obviously by reading the code i'd
say it does what i want, but we do make test cases rather than rely on what
we think the code does.

i can't run it with a target file that would be made read-only in the
filesys (and hope for an error for trying to write on it) since obviously i
need to open it in read-write right from the beginning, in case of actual
need of writing (as apparently i can't have two handles on the same file...
although maybe there's a way to change the mode of opening on the run? did
not find it in System.IO nor in Hoogle or Hayoo)

so if anyone has an idea, in or outside of haskell, that would be great!
______________________________

Maybe you can use strace? https://youtu.be/4pEHfGKB-OE


Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170627/2cfdc1b0/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 108, Issue 20
******************************************

Reply via email to