Cambridge Chat (previously New Cambridge Students Entry 2004)

Watch
This discussion is closed.
Camford
Badges: 12
Rep:
?
#8841
Report 15 years ago
#8841
(Original post by Alaric)
What are you trying to do? Have everything except the last element ?
The 2nd last element of the list. I now have function that does

> val 'a butlast = fn : 'a list -> 'a list

I want it to return 'a not 'a list.
0
Camford
Badges: 12
Rep:
?
#8842
Report 15 years ago
#8842
(Original post by Alaric)
Are there pictures?
Yep. Unfortunately. If you sell some of your dignity to the Deviless, she might let you see how "pretty" I was...
0
Camford
Badges: 12
Rep:
?
#8843
Report 15 years ago
#8843
I can't remember what the practical was asking for now... If it's asking the functions to return something other than 'a list then I'm in trouble. Here's my code:

(* Q2 *)
- fun butlast [x] = []
| butlast ([y,x]) = [y]
| butlast (x::rest) = butlast(rest);

(* Q3 *)
- fun nth (x::rest,0) = []
| nth (x::rest, 1) = [x]
| nth (x::rest, n) = nth(rest, n-1);

Alaric is not answering why my previous code takes in 'a list list and returns 'a list. So, guys (Willa, Wombat, Squishy) please feel free to destroy my half destoryed ego.
0
Alaric
Badges: 1
Rep:
?
#8844
Report 15 years ago
#8844
(Original post by Camford)
The 2nd last element of the list. I now have function that does

> val 'a butlast = fn : 'a list -> 'a list

I want it to return 'a not 'a list.
of course, ML will warn you about the elegant solution:

fun penultimate (y::x::[]) = y | penultimate (y::x::xs) = penultimate (x::xs);
0
Camford
Badges: 12
Rep:
?
#8845
Report 15 years ago
#8845
(Original post by Alaric)
of course, ML will warn you about the elegant solution:

fun penultimate (y::x::[]) = y | penultimate (y::x::xs) = penultimate (x::xs);
I got that ok... But, Dr Frank King has given out this sheet with half of the fun declarations written on it. And for this one it starts off with

fun butlast [x] = [] !!
Where do you go from there?

Edit: I need to move to bed now... otherwise, I won't make it in time for lunch. *yawns* *But shudders when the thought of himself in a bra creeps through the mind.*
0
Alaric
Badges: 1
Rep:
?
#8846
Report 15 years ago
#8846
(Original post by Camford)
I got that ok... But, Dr Frank King has given out this sheet with half of the fun declarations written on it. And for this one it starts off with

fun butlast [x] = [] !!
Where do you go from there?

Edit: I need to move to bed now... otherwise, I won't make it in time for lunch. *yawns* *But shudders when the thought of himself in a bra creeps through the mind.*
lol ok, sleep well

I can't think it's too late at night for me to do ML either, it never did like me

Alaric.
0
Camford
Badges: 12
Rep:
?
#8847
Report 15 years ago
#8847
(Original post by Alaric)
lol ok, sleep well

I can't think it's too late at night for me to do ML either, it never did like me

Alaric.
You owe me the answer to Dr King's fun declaration though... I'll chase you up for it tomorrow late in the afternoon.
0
Immortal Wombat
Badges: 0
Rep:
?
#8848
Report 15 years ago
#8848
(Original post by Alaric)
x can't be [] because then it'd be of type `a list list and not `a list. x must always be `a. [] is of type list iirc.
Ah, that would explain the odd things that kept happening. In which case, Will's question stands.
0
Willa
Badges: 9
Rep:
?
#8849
Report 15 years ago
#8849
I think you were right wombat, becuase as soon as i added a case for an empty list, the function became exhaustive.

and for the butlast thing, you just have as the second line:

| butlast(x::rest) = x :: butlast(rest);

it calls itself and will remove the last list element.
0
Willa
Badges: 9
Rep:
?
#8850
Report 15 years ago
#8850
(Original post by Camford)
- fun butlast [x] = []
| butlast (y::[x]) = y
| butlast (y::rest) = butlast (rest);

that returns

> val 'a butlast = fn : 'a list list -> 'a list

why?
this function asks for 'a list list because of your (unnecsssary) second line. That line calles for a list, where the tail end is itself a list with a head and a tail. You dont write: y::[x]....because that means: head :: (head :: tail), hence the list list

thje above function doesnt work anyway...it doesnt do what is asked!
0
Alaric
Badges: 1
Rep:
?
#8851
Report 15 years ago
#8851
(Original post by Willa)
thje above function doesnt work anyway...it doesnt do what is asked!
is it supposed to return the list apart from the last element?
0
Willa
Badges: 9
Rep:
?
#8852
Report 15 years ago
#8852
yes, which is what the function i described above does!
0
Alaric
Badges: 1
Rep:
?
#8853
Report 15 years ago
#8853
(Original post by Willa)
yes, which is what the function i described above does!
indeed it does, but Camford is trying to do a penultimate function, I don't know why!

And as a reminder to everyone, tonight is Clare Comedy - 9pm Cellars (2 or 3 pounds I think).

Alaric.
0
Willa
Badges: 9
Rep:
?
#8854
Report 15 years ago
#8854
ooo more comedy...excellent. I went to the medic revue last night and it was brill!
0
Camford
Badges: 12
Rep:
?
#8855
Report 15 years ago
#8855
(Original post by Willa)
this function asks for 'a list list because of your (unnecsssary) second line. That line calles for a list, where the tail end is itself a list with a head and a tail. You dont write: y::[x]....because that means: head :: (head :: tail), hence the list list

thje above function doesnt work anyway...it doesnt do what is asked!
Argh~~~~~~ My English is letting me down!!
0
Helenia
Badges: 20
Rep:
?
#8856
Report 15 years ago
#8856
(Original post by Willa)
ooo more comedy...excellent. I went to the medic revue last night and it was brill!
Oooh, were you there? I didn't see you! Twas indeed very good, although some material recycled from the last time I saw them.
0
Camford
Badges: 12
Rep:
?
#8857
Report 15 years ago
#8857
I'm gonna stick this link here. Enjoy the motion.
0
Willa
Badges: 9
Rep:
?
#8858
Report 15 years ago
#8858
(Original post by Helenia)
Oooh, were you there? I didn't see you! Twas indeed very good, although some material recycled from the last time I saw them.
which was your favourite sketch? The matrix one was pretty damn halarious....but i did like the gremlins one as well!
0
Helenia
Badges: 20
Rep:
?
#8859
Report 15 years ago
#8859
(Original post by Willa)
which was your favourite sketch? The matrix one was pretty damn halarious....but i did like the gremlins one as well!
I love the Matrix one, though I had seen it before. The gay scarecrows one was rather random but very good.
0
Minor_Deity
Badges: 1
Rep:
?
#8860
Report 15 years ago
#8860
(Original post by Willa)
which was your favourite sketch? The matrix one was pretty damn halarious....but i did like the gremlins one as well!
Oh oh oh! I saw the Medic's Review as well! (but on Friday). It's the reading / writing Gremlins one that has stuck in my mind, though the one about
Schroedinger's cat was very good as well. Having said that, i had had a bottle of wine beforehand...
0
X
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Had lockdown impacted your relationships?

Yes, my partner and I are struggling (33)
8.35%
Yes, my partner and I broke up (33)
8.35%
Yes, it's hard being around my family so much (88)
22.28%
Yes, I'm feeling lonely isolating alone (53)
13.42%
No, nothing has changed (118)
29.87%
No, it's helped improve my relationships (70)
17.72%

Watched Threads

View All