Questions tagged [unfold]

An unfold function is the opposite (or dual) of a fold. Unfolds recursively generate a list (or other recursive data structure) of values from a seed value.

An unfold function is the opposite (or dual) of a . Unfolds recursively generate a list (or other recursive data structure) of values from a seed value.

Unfold functions are often used functional languages which support to construct a whose values are only created on demand.

48 questions
1
vote
1 answer

Seq.cache with Seq.unfold in F#

I'm trying to cache the result of an infinite sequence of triangle numbers. let triCalc n = (n*(n+1))/2 let triNumC = 0 |> Seq.unfold (fun n -> Some((triCalc n, n+1))) |> Seq.cache However, when I try to cache it doesn't seem to work as I…
1
vote
1 answer

List coalgebra translating code from Haskell to SML

I'm trying to translate this piece of code in Haskell that describes List anamorphism but can't quite get it to work. The final three lines are supposed to generate a function count which given an int will produce an int list [n, n-1, ...,…
1
vote
1 answer

Writing a lazy-as-possible unfoldr-like function to generate arbitrary factorizations

problem formulation Informally speaking, I want to write a function which, taking as input a function that generates binary factorizations and an element (usually neutral), creates an arbitrary length factorization generator. To be more specific,…
peter pun
  • 384
  • 1
  • 8
1
vote
1 answer

How to do unfolding RFC 822

I am trying to write a vCard Parser and am having trouble unfolding lines. As you can see here: http://www.faqs.org/rfcs/rfc822.html look for "unfolding" it says that all the following are valid: Long string continue Long…
Thomaschaaf
  • 17,847
  • 32
  • 94
  • 128
1
vote
1 answer

How can I unfold the recurrence: T(n)=2T((n+2)/3)

I'm trying to solve this recurrence, but I don't know how to unfold it. T(n)=2T((n+2)/3) + 1 Can I ignore that "+2" and solve it as it was 2T(n/3) + 1? This comes from a from a problem that uses a V[a..b] array and makes this return: return V(X) +…
1
vote
2 answers

How lambda function in unfoldr can be used with two arguments in Haskell?

When reading this article I found example of generating Fibonacci sequence with unfoldr function: fibs = unfoldr (\(a,b) -> Just (a,(b,a+b))) (0,1) But when I looked at documentation I found that lambda in unfoldr function takes only one argument…
MainstreamDeveloper00
  • 8,436
  • 15
  • 56
  • 102
1
vote
1 answer

Weird couldn't match type error

I have simple one line function: revRange :: (Char,Char) -> [Char] revRange t = unfoldr (\b -> if b == (pred (fst t)) then Nothing else Just (b, pred b)) (snd t) It works well: *Main Data.List> revRange ('a', 'f') "fedcba" Then I want to extract…
David
  • 674
  • 6
  • 19
1
vote
1 answer

C#: Image unfolding to a rectangle

I need an advice in image processing. I have WF application coded in C# which finds me a coordinates by given parameters and based on this coordinates I would like to crop the image to a circle and unfold this circle to a rectangle. So just to…
0
votes
1 answer

How to solve Unfold.effects crash?

You can see problem on the picture: UndefVarError: _reference_grid not defined Some additional very strange findings: for any reason this function perfectly works in Pluto page for effect function on Unfold manual page shows 404.
0
votes
1 answer

"im2col_out_cpu" not implemented for 'Byte'

I am trying to generate overlap patches from image size (112,112) but i am unable to do so. I have already tried a lot but it didn't work out. **Code** import torch import numpy as np import torch.nn as nn from torch import nn from PIL import…
Khawar Islam
  • 2,556
  • 2
  • 34
  • 56
0
votes
1 answer

Is it possible to unfold a variadic (lambda) template and the pass those functions return value to another variadic function?

So I wonder given a variadic template function like following: template parse(int x, Fs...funcs); Where we ensure (through C++20 concept) that is convertible to std::function. Could we use unfold it into another…
0
votes
1 answer

Trying to Pattern match an integer argument "globally" within a function - Scala

First of all I apologize if the title of this is misleading, its based off what I think my issue might be. I am creating a lazy list of tuples, the end goal is to find all pythagorean triples with values less than or equal to n and rather than…
Reemz
  • 51
  • 4
0
votes
1 answer

Haskell: Efficiency iterative map with added noise

I am wondering how to improve the time performance of the white noise addition to the logistic map? The noise is only allowed to be added after calculating the values (as it is an iterative map.) module Generating import System.Random…
val
  • 1
  • 2
0
votes
1 answer

Fibonacci sequence with Unfold in Ocaml

I'm relatively new to Ocaml and think I'm understanding the Unfold function correctly but I just can't see how to make a fibonacci sequence using it. Wouldn't we need to have a holder variable of the last two values so we could find the current one?…
ohhimark
  • 11
  • 5
0
votes
0 answers

Whats going on with my Atom?

If I use unFold with shortkey on last line, it's ok. But that happens in other lines: When the focus is on the last line, everything comes back to normal.