Questions tagged [miranda]

Miranda is a pure, non-strict, polymorphic, higher order functional programming language.

For more information, see the Miranda homepage.

21 questions
342
votes
7 answers

Abusing the algebra of algebraic data types - why does this work?

The 'algebraic' expression for algebraic data types looks very suggestive to someone with a background in mathematics. Let me try to explain what I mean. Having defined the basic types Product • Union + Singleton X Unit 1 and using the shorthand…
Chris Taylor
  • 46,912
  • 15
  • 110
  • 154
8
votes
1 answer

How does lazy-evaluation allow for greater modularization?

In his article "Why Functional Programming Matters," John Hughes argues that "Lazy evaluation is perhaps the most powerful tool for modularization in the functional programmer's repertoire." To do so, he provides an example like this: Suppose you…
7
votes
2 answers

Haskell / Miranda: Find the type of the function

Brief: This is a past exam question from a Miranda exam but the syntax is very similar to Haskell. Question: What is the type of the following expression and what does it do? (The definitions of the functions length and swap are given…
user1058210
  • 1,639
  • 7
  • 29
  • 49
6
votes
3 answers

Representing Integers as Functions (Church Numerals?)

Given the following function definition and assuming similar definitions for all positive integers give the type definition and code for a function called plus that will take as arguments two such functions representing integers and return a…
5
votes
0 answers

Are there any other by default lazily evaluated languages apart from Haskell and Miranda?

On the wikipedia page only Haskell and Miranda are mentioned. I am not sure about elm. Some other languages make it especially easy to declare a function to be computed lazily. Are there programming languages where you have a global switch, say…
v217
  • 765
  • 1
  • 6
  • 17
4
votes
1 answer

Miranda Error cannot unify [[char]] with[char] on line 12

having a problem with coding with miranda am just a newbie to functional programming so slap me hard if ive dont an easy mistake so i learn anyway i a getting an error on line 12 with having a problem with unifyin char with char my idea is to check…
user23012
  • 219
  • 2
  • 16
4
votes
1 answer

Difficulty of implementing `case` expressions in a template-instantiation evaluator for a lazy functional language?

I'm following "Implementing functional languages: a tutorial" by SPJ, and I'm stuck on Exercise 2.18 (page 70), reproduced below. This is in the chapter about a template-instantiation evaluator for the simple lazy functional language described in…
3
votes
4 answers

Miranda while- and for-loops

I'm looking for a way to do while-loops or for-loops in Miranda. I'm trying to do something like while(blablanotfinished) { if(a=true)blabla else blabla }
user23012
  • 219
  • 2
  • 16
2
votes
1 answer

List comprehensions (ZF-expressions) with zero qualifiers

List comprehensions (or ZF-expressions) include a sequence of qualifiers, which can be generators or Boolean-valued expressions ("filter expressions") acting as guards. A list comprehension with no qualifier – for instance, [1 | ] – is (apparently)…
Antonielly
  • 71
  • 1
  • 4
2
votes
2 answers

Command history for mira?

Does the mira command have a shell-like history mechanism for commands typed at the terminal? I'm constantly hitting up-arrow to correct a minor typo, but it doesn't work. I'm using Miranda 2.044 for Mac OS X.
user2307360
  • 41
  • 1
  • 2
1
vote
1 answer

Missing case definition in Miranda

I'm getting a missing case definition when I'm calling this check c (n:nx) state (l:ls,r:rs) =true,if((isprefix state c)&(r=n)) =false, otherwise I've checked this and it works on its own no matter what I send it. This is where I'm calling it from…
user23012
  • 219
  • 2
  • 16
1
vote
0 answers

Canonical name for Iseq from "Implementing Functional Languages: a tutorial"

In Simon Peyton Jones's "Implementing Functional Languages: a tutorial", a data structure for efficient string building called Iseq, also referred to as iseq and iseqRep. This can be found by searching through the document. Is this Iseq name a…
Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
1
vote
1 answer

calculate average in miranda language

I really need help finding a way to calculate the average in miranda language. I seem to get this error that it cannot unify the type [num] -> num with num. I can't seem to take the sum of the list as a value and do division? elements = 4 …
1
vote
2 answers

How to read this functional code

Having trouble reading (interpreting) this functional Miranda code. g = (foldr (+) 0) . (foldr ((:) . ((#) . (:[]))) []) I know what it does Calculate the size of a list by taking the length via # Creating a one element list containing the above…
clicky
  • 865
  • 2
  • 14
  • 31
1
vote
2 answers

Miranda Type error

Can anyone tell me where goes wrong? b f x = f x (f x) My understanding is: because f at the left takes one argument but on the right side it has two arguments? Any more detail explanations?
geasssos
  • 419
  • 1
  • 5
  • 10
1
2