haskell - Unpacking a Maybe on Lists describing Deltas (and is it a Good Idea in the First Place?) -
As a newcomer to Haskell, I have been reading top rated questions, new questions etc., and today it was one of the stack overflow:
I thought, "OK, I will try Without seeing that answer. " For the beginning, I have written:
Neighbors' faults [] = [] Neighbors [a] = [] Neighbors (x: y: xs) = abs (x - y): Neighbors (Y: xs)
Then I can do at least neighbors [2,3,6,2,0,1,8,8] => 1
.
But on which side did things work, but I did not care too much, so I thought maybe I would try to use it. I would need a way to customize the recursive rule to bear a "maybe" value, so I looked at Hogel and probably found but he did not give me a One more question is usually about Haskell's mind when looking at something like that. Is it perhaps a bad use? The problem I got was trying to integrate the calculation of distance with the minimum operation. I'm assuming that you can break it without loosing important skills like this (such as it's minimum, or maximum, or whatever)? from
which seemed like I was Neighbors: [Neighbors] Neither neighbors [a] = bus [] Neighbors (x: y: xs) = bus (stomach (x - y): perhaps [] Neighbors (Y: xs))
scope: maybe
error is the main question Why would not this work be done? head
throws an exception when creating an empty list, then why a kind of refund is possible?
but he did not give me any scope: probably error from
You can import data at the top of your file. Probably (will be my)
will be required.
This offer does its own to import data. Maybe to get the definition of
maybe
, just
, and nothing
. But this, and only exports those three definitions. Therefore, less common tasks have to be manually imported.
Is this perhaps a bad use? Why make an exception to the head when making an empty list, can it be that there is a type?
head
is generally considered as a non-ideal package that provides package headmay
, which is Maybe
returns
On the other hand, I think that probably [int]
is unnecessary here. The idea of not having any valid results already in the empty list has been encoded. In fact, it is normally used as a probably
which we have and wrap it in the it
means that you spend more effort Need to 'open the values'
I'm assuming that you will be composed with significant efficiency (such as the minimum, or maximum, or whatever) without losing it in this way?
In most cases, yes is Haskell.